mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor(api): ♻️ Throw ApiError instead of returning error JSON
This commit is contained in:
parent
c14621ee06
commit
fbfd237f27
88 changed files with 458 additions and 483 deletions
24
classes/errors/api-error.ts
Normal file
24
classes/errors/api-error.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import type { ContentfulStatusCode } from "hono/utils/http-status";
|
||||
import type { JSONObject } from "hono/utils/types";
|
||||
|
||||
/**
|
||||
* API Error
|
||||
*
|
||||
* Custom error class used to throw errors in the API. Includes a status code, a message and an optional description.
|
||||
* @extends Error
|
||||
*/
|
||||
export class ApiError extends Error {
|
||||
/**
|
||||
* @param {StatusCode} status - The status code of the error
|
||||
* @param {string} message - The message of the error
|
||||
* @param {string | JSONObject} [details] - The description of the error
|
||||
*/
|
||||
public constructor(
|
||||
public status: ContentfulStatusCode,
|
||||
public message: string,
|
||||
public details?: string | JSONObject,
|
||||
) {
|
||||
super(message);
|
||||
this.name = "ApiError";
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue