mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
* refactor: unify backend and frontend servers * refactor: correct paths for openapi & drizzle * refactor: move api-client to client * fix: drizzle paths * chore: fix linting issues * fix: form reset issue
20 lines
679 B
TypeScript
20 lines
679 B
TypeScript
import { ConflictError, NotFoundError } from "http-errors-enhanced";
|
|
import { sanitizeSensitiveData } from "./sanitize";
|
|
|
|
export const handleServiceError = (error: unknown) => {
|
|
if (error instanceof ConflictError) {
|
|
return { message: sanitizeSensitiveData(error.message), status: 409 as const };
|
|
}
|
|
|
|
if (error instanceof NotFoundError) {
|
|
return { message: sanitizeSensitiveData(error.message), status: 404 as const };
|
|
}
|
|
|
|
return { message: sanitizeSensitiveData(toMessage(error)), status: 500 as const };
|
|
};
|
|
|
|
export const toMessage = (err: unknown): string => {
|
|
const message = err instanceof Error ? err.message : String(err);
|
|
return sanitizeSensitiveData(message);
|
|
};
|