@saihu/common 1.0.9 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dto/base-res.dto.d.ts +14 -0
- package/dist/dto/base-res.dto.js +32 -1
- package/package.json +1 -1
|
@@ -12,3 +12,17 @@ export declare class BaseResponseDto<T> {
|
|
|
12
12
|
static readonly CODE_BAD_REQUEST = 400;
|
|
13
13
|
static readonly CODE_SERVER_ERROR = 500;
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* BaseError - A throwable error that contains BaseResponseDto information
|
|
17
|
+
*/
|
|
18
|
+
export declare class BaseError extends Error {
|
|
19
|
+
code: number;
|
|
20
|
+
data: any | null;
|
|
21
|
+
constructor(code: number, message: string, data?: any);
|
|
22
|
+
toResponse<T>(): BaseResponseDto<T>;
|
|
23
|
+
static notFound(message?: string): BaseError;
|
|
24
|
+
static unauthorized(message?: string): BaseError;
|
|
25
|
+
static forbidden(message?: string): BaseError;
|
|
26
|
+
static badRequest(message?: string): BaseError;
|
|
27
|
+
static serverError(message?: string): BaseError;
|
|
28
|
+
}
|
package/dist/dto/base-res.dto.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseResponseDto = void 0;
|
|
3
|
+
exports.BaseError = exports.BaseResponseDto = void 0;
|
|
4
4
|
// src/dto/base-response.dto.ts
|
|
5
5
|
class BaseResponseDto {
|
|
6
6
|
constructor(code, msg, data = null) {
|
|
@@ -25,3 +25,34 @@ BaseResponseDto.CODE_UNAUTHORIZED = 401;
|
|
|
25
25
|
BaseResponseDto.CODE_FORBIDDEN = 403;
|
|
26
26
|
BaseResponseDto.CODE_BAD_REQUEST = 400;
|
|
27
27
|
BaseResponseDto.CODE_SERVER_ERROR = 500;
|
|
28
|
+
/**
|
|
29
|
+
* BaseError - A throwable error that contains BaseResponseDto information
|
|
30
|
+
*/
|
|
31
|
+
class BaseError extends Error {
|
|
32
|
+
constructor(code, message, data = null) {
|
|
33
|
+
super(message);
|
|
34
|
+
this.name = 'BaseError';
|
|
35
|
+
this.code = code;
|
|
36
|
+
this.data = data;
|
|
37
|
+
}
|
|
38
|
+
toResponse() {
|
|
39
|
+
return new BaseResponseDto(this.code, this.message, this.data);
|
|
40
|
+
}
|
|
41
|
+
// Static methods for common errors
|
|
42
|
+
static notFound(message = 'Resource not found') {
|
|
43
|
+
return new BaseError(BaseResponseDto.CODE_NOT_FOUND, message);
|
|
44
|
+
}
|
|
45
|
+
static unauthorized(message = 'Unauthorized') {
|
|
46
|
+
return new BaseError(BaseResponseDto.CODE_UNAUTHORIZED, message);
|
|
47
|
+
}
|
|
48
|
+
static forbidden(message = 'Forbidden') {
|
|
49
|
+
return new BaseError(BaseResponseDto.CODE_FORBIDDEN, message);
|
|
50
|
+
}
|
|
51
|
+
static badRequest(message = 'Bad request') {
|
|
52
|
+
return new BaseError(BaseResponseDto.CODE_BAD_REQUEST, message);
|
|
53
|
+
}
|
|
54
|
+
static serverError(message = 'Internal server error') {
|
|
55
|
+
return new BaseError(BaseResponseDto.CODE_SERVER_ERROR, message);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.BaseError = BaseError;
|