mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-11 16:20:13 +00:00
Merge branch 'main' of github/Draconizations/pk-webs-svelte into feat/dashboard
This commit is contained in:
commit
8fa371bcc8
56 changed files with 6420 additions and 0 deletions
28
dashboard/src/api/errors.ts
Normal file
28
dashboard/src/api/errors.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
enum ErrorType {
|
||||
Unknown = 0,
|
||||
InvalidToken = 401,
|
||||
NotFound = 404,
|
||||
InternalServerError = 500,
|
||||
}
|
||||
|
||||
interface ApiError {
|
||||
code: number,
|
||||
type: ErrorType,
|
||||
message?: string,
|
||||
data?: any,
|
||||
}
|
||||
|
||||
export function parse(code: number, data?: any): ApiError {
|
||||
var type = ErrorType[ErrorType[code]] ?? ErrorType.Unknown;
|
||||
if (code >= 500) type = ErrorType.InternalServerError;
|
||||
|
||||
var err: ApiError = { code, type };
|
||||
|
||||
if (data) {
|
||||
var d = data;
|
||||
err.message = d.message;
|
||||
err.data = d;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue