mirror of
https://github.com/Nezumi-2711/next-gdrive-index.git
synced 2026-09-22 20:01:36 +00:00
35 lines
916 B
TypeScript
35 lines
916 B
TypeScript
import ExtendedError from "utils/generalHelper/extendedError";
|
|
|
|
import { API_Error } from "types/api";
|
|
import { Constant } from "types/general/constant";
|
|
|
|
function createErrorPayload(
|
|
error: any,
|
|
path: string,
|
|
requestStart: number = Date.now(),
|
|
): API_Error {
|
|
console.error(`Error @${path}: `, error.message);
|
|
|
|
const payload: API_Error = {
|
|
success: false,
|
|
timestamp: new Date().toISOString(),
|
|
responseTime: Date.now() - requestStart,
|
|
code: error.code || 500,
|
|
message: Constant.apiInternalError,
|
|
category: "internalError",
|
|
reason: error.message || Constant.apiInternalError,
|
|
};
|
|
|
|
if (error instanceof ExtendedError) {
|
|
console.log(error.message);
|
|
payload.message = error.message;
|
|
payload.category = error.category || "internalError";
|
|
payload.reason =
|
|
error.reason || Constant.apiInternalError;
|
|
}
|
|
|
|
return payload;
|
|
}
|
|
|
|
export default createErrorPayload;
|