errors: added ServiceUnavailableError
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user