Files
pihka-al/app/utils/api.ts
Pihkaal 27cb044247
All checks were successful
Deploy / build (push) Successful in 12m22s
Deploy / deploy (push) Successful in 1s
feat: use portainer hook instead of pushing image to gitea package repository
2026-05-30 23:25:50 +02:00

27 lines
755 B
TypeScript

import { z } from "zod";
import type { InternalApi } from "nitropack/types";
export type Link = InternalApi["/api/links"]["get"][number];
export type FileEntry = { name: string; size: number; modifiedAt: string };
const apiErrorSchema = z.object({
data: z.object({
statusCode: z.number(),
message: z.string(),
}),
});
export const getApiError = (
error: unknown,
defaultMessage: string = "Something went wrong",
): string => {
const parsedError = apiErrorSchema.safeParse(error);
if (parsedError.success) {
if (parsedError.data.data.statusCode === 500) {
return `ERR-500: Internal server error`;
}
return `ERR-${parsedError.data.data.statusCode}: ${parsedError.data.data.message}`;
}
return defaultMessage;
};