2023-03-17 17:42:31 +00:00
|
|
|
import type { SwaggerMessage } from "@/types/swagger.type";
|
|
|
|
|
|
|
|
const STATUS_CODE_MAP: Record<number, string> = {
|
|
|
|
400: "Bad Request",
|
|
|
|
401: "Unauthorized",
|
|
|
|
404: "Not Found",
|
|
|
|
409: "Conflict",
|
|
|
|
500: "Internal Server Error",
|
|
|
|
};
|
|
|
|
|
|
|
|
export const swaggerError = (code: number, message: string): SwaggerMessage => ({
|
|
|
|
type: "object",
|
|
|
|
description: STATUS_CODE_MAP[code],
|
|
|
|
properties: {
|
|
|
|
statusCode: { type: "integer" },
|
|
|
|
error: { type: "string" },
|
|
|
|
message: { type: "string" },
|
|
|
|
},
|
|
|
|
examples: [{ statusCode: code, error: STATUS_CODE_MAP[code], message: message }],
|
|
|
|
});
|