mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-28 00:06:53 +01:00
23a874d051
* refactor: convert remaining js files to typescript * refactor: conditionally render remove index * refactor: dialog component to tsx * refactor: migrate some files from jsx to tsx * refactor: convert dropdown element to tsx * refactor: feature toggle list to tsx * refactor: update context name in use overrides * refactor: variant overrides to tsx refactor: remove unused strategy constraint file * fix: tsx imports * fix: update refectored components after rebase * refactor: rename report list files to tsx * fix: project health list types * refactor: addon form - add types * refactor: copy feature component types * fix: projects toggle style after tsx refactor * refactor: update ts types from openapi * fix: ts refactor changes after review * fix: header title prop * fix: update after PR comments * add test to useoverrides hook * fix conditionally render time ago * fix: toggle list empty tooltip * fix: remove unused variable * remove unused variable * fix: remove faulty snapshot
66 lines
1.6 KiB
TypeScript
66 lines
1.6 KiB
TypeScript
import {
|
|
BAD_REQUEST,
|
|
FORBIDDEN,
|
|
NOT_FOUND,
|
|
UNAUTHORIZED,
|
|
} from 'constants/statusCodes';
|
|
|
|
export interface IErrorBody {
|
|
details?: { message: string }[];
|
|
}
|
|
|
|
export class AuthenticationError extends Error {
|
|
statusCode: number;
|
|
|
|
constructor(statusCode: number = UNAUTHORIZED) {
|
|
super('Authentication required');
|
|
this.name = 'AuthenticationError';
|
|
this.statusCode = statusCode;
|
|
}
|
|
}
|
|
|
|
export class ForbiddenError extends Error {
|
|
statusCode: number;
|
|
body: IErrorBody;
|
|
|
|
constructor(statusCode: number = FORBIDDEN, body: IErrorBody = {}) {
|
|
super(
|
|
body.details?.length
|
|
? body.details[0].message
|
|
: 'You cannot perform this action'
|
|
);
|
|
this.name = 'ForbiddenError';
|
|
this.statusCode = statusCode;
|
|
this.body = body;
|
|
}
|
|
}
|
|
|
|
export class BadRequestError extends Error {
|
|
statusCode: number;
|
|
body: IErrorBody;
|
|
|
|
constructor(statusCode: number = BAD_REQUEST, body: IErrorBody = {}) {
|
|
super(body.details?.length ? body.details[0].message : 'Bad request');
|
|
this.name = 'BadRequestError';
|
|
this.statusCode = statusCode;
|
|
this.body = body;
|
|
}
|
|
}
|
|
|
|
export class NotFoundError extends Error {
|
|
statusCode: number;
|
|
|
|
constructor(statusCode: number = NOT_FOUND) {
|
|
super(
|
|
'The requested resource could not be found but may be available in the future'
|
|
);
|
|
this.name = 'NotFoundError';
|
|
this.statusCode = statusCode;
|
|
}
|
|
}
|
|
|
|
export const headers = {
|
|
Accept: 'application/json',
|
|
'Content-Type': 'application/json',
|
|
};
|