Merge pull request #17982 from idakucamupeva/error-name-handling
Add name parameter to CustomErrorBase class
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/errors': patch
|
||||
---
|
||||
|
||||
Set `this.name` in all error classes that extend `CustomErrorBase` class to their actual name
|
||||
@@ -9,10 +9,16 @@ import { JsonObject } from '@backstage/types';
|
||||
export function assertError(value: unknown): asserts value is ErrorLike;
|
||||
|
||||
// @public
|
||||
export class AuthenticationError extends CustomErrorBase {}
|
||||
export class AuthenticationError extends CustomErrorBase {
|
||||
// (undocumented)
|
||||
name: 'AuthenticationError';
|
||||
}
|
||||
|
||||
// @public
|
||||
export class ConflictError extends CustomErrorBase {}
|
||||
export class ConflictError extends CustomErrorBase {
|
||||
// (undocumented)
|
||||
name: 'ConflictError';
|
||||
}
|
||||
|
||||
// @public
|
||||
export type ConsumedResponse = {
|
||||
@@ -73,22 +79,37 @@ export class ForwardedError extends CustomErrorBase {
|
||||
}
|
||||
|
||||
// @public
|
||||
export class InputError extends CustomErrorBase {}
|
||||
export class InputError extends CustomErrorBase {
|
||||
// (undocumented)
|
||||
name: 'InputError';
|
||||
}
|
||||
|
||||
// @public
|
||||
export function isError(value: unknown): value is ErrorLike;
|
||||
|
||||
// @public
|
||||
export class NotAllowedError extends CustomErrorBase {}
|
||||
export class NotAllowedError extends CustomErrorBase {
|
||||
// (undocumented)
|
||||
name: 'NotAllowedError';
|
||||
}
|
||||
|
||||
// @public
|
||||
export class NotFoundError extends CustomErrorBase {}
|
||||
export class NotFoundError extends CustomErrorBase {
|
||||
// (undocumented)
|
||||
name: 'NotFoundError';
|
||||
}
|
||||
|
||||
// @public
|
||||
export class NotImplementedError extends CustomErrorBase {}
|
||||
export class NotImplementedError extends CustomErrorBase {
|
||||
// (undocumented)
|
||||
name: 'NotImplementedError';
|
||||
}
|
||||
|
||||
// @public
|
||||
export class NotModifiedError extends CustomErrorBase {}
|
||||
export class NotModifiedError extends CustomErrorBase {
|
||||
// (undocumented)
|
||||
name: 'NotModifiedError';
|
||||
}
|
||||
|
||||
// @public
|
||||
export function parseErrorResponseBody(
|
||||
|
||||
@@ -22,8 +22,11 @@ import { isError } from './assertion';
|
||||
*
|
||||
* @public
|
||||
* @example
|
||||
*```ts
|
||||
* class MyCustomError extends CustomErrorBase {}
|
||||
*
|
||||
* ```ts
|
||||
* class MyCustomError extends CustomErrorBase {
|
||||
* name = 'MyCustomError' as const;
|
||||
* }
|
||||
*
|
||||
* const e = new MyCustomError('Some message', cause);
|
||||
* // e.name === 'MyCustomError'
|
||||
@@ -53,7 +56,13 @@ export class CustomErrorBase extends Error {
|
||||
|
||||
Error.captureStackTrace?.(this, this.constructor);
|
||||
|
||||
this.name = this.constructor.name;
|
||||
if (!this.name || this.name === 'Error') {
|
||||
const baseName = this.constructor.name;
|
||||
if (baseName !== 'Error') {
|
||||
this.name = this.constructor.name;
|
||||
}
|
||||
}
|
||||
|
||||
this.cause = isError(cause) ? cause : undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,21 +33,27 @@ import { CustomErrorBase } from './CustomErrorBase';
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class InputError extends CustomErrorBase {}
|
||||
export class InputError extends CustomErrorBase {
|
||||
name = 'InputError' as const;
|
||||
}
|
||||
|
||||
/**
|
||||
* The request requires authentication, which was not properly supplied.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class AuthenticationError extends CustomErrorBase {}
|
||||
export class AuthenticationError extends CustomErrorBase {
|
||||
name = 'AuthenticationError' as const;
|
||||
}
|
||||
|
||||
/**
|
||||
* The authenticated caller is not allowed to perform this request.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class NotAllowedError extends CustomErrorBase {}
|
||||
export class NotAllowedError extends CustomErrorBase {
|
||||
name = 'NotAllowedError' as const;
|
||||
}
|
||||
|
||||
/**
|
||||
* The requested resource could not be found.
|
||||
@@ -57,7 +63,9 @@ export class NotAllowedError extends CustomErrorBase {}
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class NotFoundError extends CustomErrorBase {}
|
||||
export class NotFoundError extends CustomErrorBase {
|
||||
name = 'NotFoundError' as const;
|
||||
}
|
||||
|
||||
/**
|
||||
* The request could not complete due to a conflict in the current state of the
|
||||
@@ -65,21 +73,27 @@ export class NotFoundError extends CustomErrorBase {}
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class ConflictError extends CustomErrorBase {}
|
||||
export class ConflictError extends CustomErrorBase {
|
||||
name = 'ConflictError' as const;
|
||||
}
|
||||
|
||||
/**
|
||||
* The requested resource has not changed since last request.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class NotModifiedError extends CustomErrorBase {}
|
||||
export class NotModifiedError extends CustomErrorBase {
|
||||
name = 'NotModifiedError' as const;
|
||||
}
|
||||
|
||||
/**
|
||||
* The server does not support the functionality required to fulfill the request.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class NotImplementedError extends CustomErrorBase {}
|
||||
export class NotImplementedError extends CustomErrorBase {
|
||||
name = 'NotImplementedError' as const;
|
||||
}
|
||||
|
||||
/**
|
||||
* The server is not ready to handle the request.
|
||||
|
||||
Reference in New Issue
Block a user