capitalize error message

Let's not assume, nor force, that the backend provides error messages
in a format that we want to present. Hence we capitalize ourselves
for consistency.
This commit is contained in:
Sebastian Thiel 2024-06-01 15:47:10 +02:00
parent 83893a9db3
commit dedd721dc3
No known key found for this signature in database
GPG Key ID: 9CB5EE7895E8268B

View File

@ -22,10 +22,17 @@ export class UserError extends Error {
const cause = error instanceof Error ? error : undefined;
const code = error.code ?? Code.Unknown;
const message = error.message ?? error;
return new UserError(message, code, cause);
return new UserError(capitalize(message), code, cause);
}
}
function capitalize(str: string): string {
if (str.length === 0) {
return str;
}
return str.charAt(0).toUpperCase() + str.slice(1);
}
export async function invoke<T>(command: string, params: Record<string, unknown> = {}): Promise<T> {
// This commented out code can be used to delay/reject an api call
// return new Promise<T>((resolve, reject) => {