mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
20 lines
601 B
TypeScript
20 lines
601 B
TypeScript
import { ConflictError, NotFoundError } from "http-errors-enhanced";
|
|
import { logger } from "./logger";
|
|
|
|
export const handleServiceError = (error: unknown) => {
|
|
if (error instanceof ConflictError) {
|
|
return { message: error.message, status: 409 as const };
|
|
}
|
|
|
|
if (error instanceof NotFoundError) {
|
|
return { message: error.message, status: 404 as const };
|
|
}
|
|
|
|
logger.error("Unhandled service error:", error);
|
|
return { message: "Internal Server Error", status: 500 as const };
|
|
};
|
|
|
|
export const toMessage = (err: unknown): string => {
|
|
return err instanceof Error ? err.message : String(err);
|
|
};
|