Use promise Router & add known error in Vault backend

Signed-off-by: ivgo <ivgo@spreadgroup.com>
This commit is contained in:
ivgo
2022-11-21 15:00:45 +01:00
parent 2abe080e8d
commit 7a3d2688ed
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}'`,