2023-07-27 05:31:52 +00:00
|
|
|
/*
|
2024-02-13 15:59:27 +00:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 05:31:52 +00:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-09-17 18:27:08 +00:00
|
|
|
export class StatusError extends Error {
|
|
|
|
public statusCode: number;
|
|
|
|
public statusMessage?: string;
|
|
|
|
public isClientError: boolean;
|
2024-01-06 00:40:08 +00:00
|
|
|
public isRetryable: boolean;
|
2022-09-17 18:27:08 +00:00
|
|
|
|
|
|
|
constructor(message: string, statusCode: number, statusMessage?: string) {
|
|
|
|
super(message);
|
|
|
|
this.name = 'StatusError';
|
|
|
|
this.statusCode = statusCode;
|
|
|
|
this.statusMessage = statusMessage;
|
|
|
|
this.isClientError = typeof this.statusCode === 'number' && this.statusCode >= 400 && this.statusCode < 500;
|
2024-01-06 00:40:08 +00:00
|
|
|
this.isRetryable = !this.isClientError || this.statusCode === 429;
|
2022-09-17 18:27:08 +00:00
|
|
|
}
|
|
|
|
}
|