errors: added ServiceUnavailableError
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/errors': minor
|
||||
---
|
||||
|
||||
Added `ServiceUnavailableError`
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/backend-app-api': patch
|
||||
---
|
||||
|
||||
Added handling of `ServiceUnavailableError` to error handling middleware.
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
NotAllowedError,
|
||||
NotFoundError,
|
||||
NotModifiedError,
|
||||
ServiceUnavailableError,
|
||||
} from '@backstage/errors';
|
||||
import express from 'express';
|
||||
import createError from 'http-errors';
|
||||
@@ -143,6 +144,9 @@ describe('MiddlewareFactory', () => {
|
||||
app.use('/ConflictError', () => {
|
||||
throw new ConflictError();
|
||||
});
|
||||
app.use('/ServiceUnavailableError', () => {
|
||||
throw new ServiceUnavailableError();
|
||||
});
|
||||
app.use(middleware.error());
|
||||
|
||||
const r = request(app);
|
||||
@@ -165,6 +169,10 @@ describe('MiddlewareFactory', () => {
|
||||
expect((await r.get('/ConflictError')).body.error.name).toBe(
|
||||
'ConflictError',
|
||||
);
|
||||
expect((await r.get('/ServiceUnavailableError')).status).toBe(503);
|
||||
expect((await r.get('/ServiceUnavailableError')).body.error.name).toBe(
|
||||
'ServiceUnavailableError',
|
||||
);
|
||||
});
|
||||
|
||||
it('logs all 500 errors', async () => {
|
||||
|
||||
@@ -36,6 +36,7 @@ import {
|
||||
NotAllowedError,
|
||||
NotFoundError,
|
||||
NotModifiedError,
|
||||
ServiceUnavailableError,
|
||||
serializeError,
|
||||
} from '@backstage/errors';
|
||||
import { NotImplementedError } from '@backstage/errors';
|
||||
@@ -260,6 +261,8 @@ function getStatusCode(error: Error): number {
|
||||
return 409;
|
||||
case NotImplementedError.name:
|
||||
return 501;
|
||||
case ServiceUnavailableError.name:
|
||||
return 503;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -125,6 +125,9 @@ export function serializeError(
|
||||
},
|
||||
): SerializedError;
|
||||
|
||||
// @public
|
||||
export class ServiceUnavailableError extends CustomErrorBase {}
|
||||
|
||||
// @public
|
||||
export function stringifyError(error: unknown): string;
|
||||
```
|
||||
|
||||
@@ -81,6 +81,13 @@ export class NotModifiedError extends CustomErrorBase {}
|
||||
*/
|
||||
export class NotImplementedError extends CustomErrorBase {}
|
||||
|
||||
/**
|
||||
* The server is not ready to handle the request.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class ServiceUnavailableError extends CustomErrorBase {}
|
||||
|
||||
/**
|
||||
* An error that forwards an underlying cause with additional context in the message.
|
||||
*
|
||||
|
||||
@@ -25,6 +25,7 @@ export {
|
||||
NotFoundError,
|
||||
NotModifiedError,
|
||||
NotImplementedError,
|
||||
ServiceUnavailableError,
|
||||
} from './common';
|
||||
export { CustomErrorBase } from './CustomErrorBase';
|
||||
export { ResponseError } from './ResponseError';
|
||||
|
||||
Reference in New Issue
Block a user