Merge pull request #33917 from backstage/rugvip/add-service-unavailable-error-name
errors: add explicit name property to ServiceUnavailableError
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/errors': patch
|
||||
---
|
||||
|
||||
Added explicit `name` property to `ServiceUnavailableError` for consistency with all other error classes, making it resilient to minification.
|
||||
@@ -151,7 +151,10 @@ export function serializeError(
|
||||
): SerializedError;
|
||||
|
||||
// @public
|
||||
export class ServiceUnavailableError extends CustomErrorBase {}
|
||||
export class ServiceUnavailableError extends CustomErrorBase {
|
||||
// (undocumented)
|
||||
name: 'ServiceUnavailableError';
|
||||
}
|
||||
|
||||
// @public
|
||||
export function stringifyError(error: unknown): string;
|
||||
|
||||
@@ -100,7 +100,9 @@ export class NotImplementedError extends CustomErrorBase {
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class ServiceUnavailableError extends CustomErrorBase {}
|
||||
export class ServiceUnavailableError extends CustomErrorBase {
|
||||
name = 'ServiceUnavailableError' as const;
|
||||
}
|
||||
|
||||
/**
|
||||
* An error that forwards an underlying cause with additional context in the message.
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { NotModifiedError } from '../errors';
|
||||
import { NotModifiedError, ServiceUnavailableError } from '../errors';
|
||||
import { deserializeError, serializeError, stringifyError } from './error';
|
||||
|
||||
class CustomError extends Error {
|
||||
@@ -77,6 +77,16 @@ describe('serialization', () => {
|
||||
expect(withoutStack2.cause.stack).not.toBeDefined();
|
||||
});
|
||||
|
||||
it('round-trips a ServiceUnavailableError', () => {
|
||||
const before = new ServiceUnavailableError('service down');
|
||||
const after = deserializeError(
|
||||
serializeError(before, { includeStack: true }),
|
||||
);
|
||||
expect(after.name).toEqual('ServiceUnavailableError');
|
||||
expect(after.message).toEqual('service down');
|
||||
expect(after.stack).toEqual(before.stack);
|
||||
});
|
||||
|
||||
it('stringifies all supported forms', () => {
|
||||
expect(stringifyError({})).toEqual("unknown error '[object Object]'");
|
||||
expect(
|
||||
|
||||
Reference in New Issue
Block a user