2022-02-25 10:55:39 +01:00
|
|
|
export interface IErrorBody {
|
|
|
|
details?: { message: string }[];
|
|
|
|
}
|
2022-02-11 11:19:55 +01:00
|
|
|
|
|
|
|
export class AuthenticationError extends Error {
|
2022-02-25 10:55:39 +01:00
|
|
|
statusCode: number;
|
|
|
|
|
|
|
|
constructor(statusCode: number) {
|
2022-02-11 11:19:55 +01:00
|
|
|
super('Authentication required');
|
|
|
|
this.name = 'AuthenticationError';
|
|
|
|
this.statusCode = statusCode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class ForbiddenError extends Error {
|
2022-02-25 10:55:39 +01:00
|
|
|
statusCode: number;
|
|
|
|
body: IErrorBody;
|
|
|
|
|
|
|
|
constructor(statusCode: number, body: IErrorBody = {}) {
|
2022-02-11 11:19:55 +01:00
|
|
|
super(
|
2022-02-25 10:55:39 +01:00
|
|
|
body.details?.length
|
2022-02-11 11:19:55 +01:00
|
|
|
? body.details[0].message
|
|
|
|
: 'You cannot perform this action'
|
|
|
|
);
|
|
|
|
this.name = 'ForbiddenError';
|
|
|
|
this.statusCode = statusCode;
|
|
|
|
this.body = body;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class BadRequestError extends Error {
|
2022-02-25 10:55:39 +01:00
|
|
|
statusCode: number;
|
|
|
|
body: IErrorBody;
|
|
|
|
|
|
|
|
constructor(statusCode: number, body: IErrorBody = {}) {
|
|
|
|
super(body.details?.length ? body.details[0].message : 'Bad request');
|
2022-02-11 11:19:55 +01:00
|
|
|
this.name = 'BadRequestError';
|
|
|
|
this.statusCode = statusCode;
|
|
|
|
this.body = body;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class NotFoundError extends Error {
|
2022-02-25 10:55:39 +01:00
|
|
|
statusCode: number;
|
|
|
|
|
|
|
|
constructor(statusCode: number) {
|
2022-02-11 11:19:55 +01:00
|
|
|
super(
|
|
|
|
'The requested resource could not be found but may be available in the future'
|
|
|
|
);
|
|
|
|
this.name = 'NotFoundError';
|
|
|
|
this.statusCode = statusCode;
|
|
|
|
}
|
|
|
|
}
|
2022-02-25 10:55:39 +01:00
|
|
|
|
|
|
|
export const headers = {
|
|
|
|
Accept: 'application/json',
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
};
|