mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
refactor(core): standardize frontend error handling (#10667)
This commit is contained in:
@@ -5,6 +5,7 @@ import { HttpStatus, Logger } from '@nestjs/common';
|
||||
import { ClsServiceManager } from 'nestjs-cls';
|
||||
|
||||
export type UserFriendlyErrorBaseType =
|
||||
| 'network_error'
|
||||
| 'bad_request'
|
||||
| 'too_many_requests'
|
||||
| 'resource_not_found'
|
||||
@@ -26,6 +27,7 @@ export type UserFriendlyErrorOptions = {
|
||||
};
|
||||
|
||||
const BaseTypeToHttpStatusMap: Record<UserFriendlyErrorBaseType, HttpStatus> = {
|
||||
network_error: HttpStatus.GATEWAY_TIMEOUT,
|
||||
too_many_requests: HttpStatus.TOO_MANY_REQUESTS,
|
||||
bad_request: HttpStatus.BAD_REQUEST,
|
||||
resource_not_found: HttpStatus.NOT_FOUND,
|
||||
@@ -239,6 +241,10 @@ export const USER_FRIENDLY_ERRORS = {
|
||||
type: 'internal_server_error',
|
||||
message: 'An internal error occurred.',
|
||||
},
|
||||
network_error: {
|
||||
type: 'network_error',
|
||||
message: 'Network error.',
|
||||
},
|
||||
too_many_request: {
|
||||
type: 'too_many_requests',
|
||||
message: 'Too many requests.',
|
||||
|
||||
@@ -10,6 +10,12 @@ export class InternalServerError extends UserFriendlyError {
|
||||
}
|
||||
}
|
||||
|
||||
export class NetworkError extends UserFriendlyError {
|
||||
constructor(message?: string) {
|
||||
super('network_error', 'network_error', message);
|
||||
}
|
||||
}
|
||||
|
||||
export class TooManyRequest extends UserFriendlyError {
|
||||
constructor(message?: string) {
|
||||
super('too_many_requests', 'too_many_request', message);
|
||||
@@ -851,6 +857,7 @@ export class UnsupportedClientVersion extends UserFriendlyError {
|
||||
}
|
||||
export enum ErrorNames {
|
||||
INTERNAL_SERVER_ERROR,
|
||||
NETWORK_ERROR,
|
||||
TOO_MANY_REQUEST,
|
||||
NOT_FOUND,
|
||||
BAD_REQUEST,
|
||||
|
||||
Reference in New Issue
Block a user