feat: 添加 NestJS API 基础设施
This commit is contained in:
@@ -22,6 +22,10 @@ describe("contracts", () => {
|
||||
it("defines the complete error-code contract", () => {
|
||||
expect(Object.values(ErrorCode)).toEqual([
|
||||
"OK",
|
||||
"VALIDATION_ERROR",
|
||||
"NOT_FOUND",
|
||||
"SERVICE_UNAVAILABLE",
|
||||
"INTERNAL_ERROR",
|
||||
"AUTH_TOKEN_EXPIRED",
|
||||
"AUTH_REFRESH_REUSED",
|
||||
"BOTTLE_DAILY_LIMIT",
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
export enum ErrorCode {
|
||||
OK = "OK",
|
||||
VALIDATION_ERROR = "VALIDATION_ERROR",
|
||||
NOT_FOUND = "NOT_FOUND",
|
||||
SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE",
|
||||
INTERNAL_ERROR = "INTERNAL_ERROR",
|
||||
AUTH_TOKEN_EXPIRED = "AUTH_TOKEN_EXPIRED",
|
||||
AUTH_REFRESH_REUSED = "AUTH_REFRESH_REUSED",
|
||||
BOTTLE_DAILY_LIMIT = "BOTTLE_DAILY_LIMIT",
|
||||
@@ -18,6 +22,13 @@ export interface SuccessResponse<T> {
|
||||
requestId: string;
|
||||
}
|
||||
|
||||
export interface ErrorResponse {
|
||||
code: Exclude<ErrorCode, ErrorCode.OK>;
|
||||
message: string;
|
||||
data: null;
|
||||
requestId: string;
|
||||
}
|
||||
|
||||
export const ok = <T>(data: T, requestId: string): SuccessResponse<T> => ({
|
||||
code: ErrorCode.OK,
|
||||
message: "success",
|
||||
|
||||
Reference in New Issue
Block a user