Manage errors

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2025-10-29 14:03:50 +01:00
parent 55743cbb5c
commit 9a33f7b771
84 changed files with 1483 additions and 331 deletions

View File

@@ -0,0 +1,26 @@
export interface GraphQLError {
message?: string;
source?: {
errors?: Array<{ message: string }>;
};
}
export function formatError(title: string, error: GraphQLError | GraphQLError[]): string {
const messages: string[] = [];
if (Array.isArray(error)) {
messages.push(...error.map((e) => e.message).filter(Boolean) as string[]);
} else if (error.source?.errors && Array.isArray(error.source.errors)) {
messages.push(...error.source.errors.map((e) => e.message).filter(Boolean));
} else if (error.message) {
messages.push(error.message);
}
if (messages.length === 0) {
return title;
}
const errorList = messages.join(", ");
return `${title}: ${errorList}${errorList.endsWith('.') ? '' : '.'}`;
}

View File

@@ -59,3 +59,4 @@ export { promisifyMutation } from "./relay";
export { fileType, fileSize } from "./file";
export { formatDatetime, formatDate } from "./date";
export { getLogoUrl, getTrustCenterUrl } from "./trustCenter";
export { formatError, type GraphQLError } from "./error";