Merge pull request #14732 from ivangonzalezacuna/fix/vault-routing

Use promise Router & add known error in Vault backend
This commit is contained in:
Fredrik Adelöw
2022-11-21 16:01:41 +01:00
committed by GitHub
3 changed files with 11 additions and 2 deletions
+6
View File
@@ -0,0 +1,6 @@
---
'@backstage/plugin-vault-backend': patch
---
Use `express-promise-router` to catch errors properly.
Add `403` error as a known one. It will now return a `NotAllowed` error.
@@ -17,7 +17,8 @@
import { Config } from '@backstage/config';
import { InputError } from '@backstage/errors';
import { Logger } from 'winston';
import express, { Router } from 'express';
import express from 'express';
import Router from 'express-promise-router';
import { VaultClient } from './vaultApi';
import { TaskRunner, PluginTaskScheduler } from '@backstage/backend-tasks';
import { errorHandler } from '@backstage/backend-common';
@@ -15,7 +15,7 @@
*/
import { Config } from '@backstage/config';
import { NotFoundError } from '@backstage/errors';
import { NotAllowedError, NotFoundError } from '@backstage/errors';
import fetch from 'node-fetch';
import plimit from 'p-limit';
import { getVaultConfig, VaultConfig } from '../config';
@@ -103,6 +103,8 @@ export class VaultClient implements VaultApi {
return (await response.json()) as T;
} else if (response.status === 404) {
throw new NotFoundError(`No secrets found in path '${path}'`);
} else if (response.status === 403) {
throw new NotAllowedError(response.statusText);
}
throw new Error(
`Unexpected error while fetching secrets from path '${path}'`,