
* Fixes error types * Type fixes * Refactors video meeting handling * More type fixes * Type fixes * More fixes * Makes language non optional * Adds missing translations * Apply suggestions from code review Co-authored-by: Alex Johansson <alexander@n1s.se> * Feedback Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Alex Johansson <alexander@n1s.se>
32 lines
873 B
TypeScript
32 lines
873 B
TypeScript
import { Prisma } from "@prisma/client";
|
|
|
|
export function getErrorFromUnknown(cause: unknown): Error & { statusCode?: number; code?: string } {
|
|
if (cause instanceof Prisma.PrismaClientKnownRequestError) {
|
|
return cause;
|
|
}
|
|
if (cause instanceof Error) {
|
|
return cause;
|
|
}
|
|
if (typeof cause === "string") {
|
|
// @ts-expect-error https://github.com/tc39/proposal-error-cause
|
|
return new Error(cause, { cause });
|
|
}
|
|
|
|
return new Error(`Unhandled error of type '${typeof cause}''`);
|
|
}
|
|
|
|
export function handleErrorsJson(response: Response) {
|
|
if (!response.ok) {
|
|
response.json().then(console.log);
|
|
throw Error(response.statusText);
|
|
}
|
|
return response.json();
|
|
}
|
|
|
|
export function handleErrorsRaw(response: Response) {
|
|
if (!response.ok) {
|
|
response.text().then(console.log);
|
|
throw Error(response.statusText);
|
|
}
|
|
return response.text();
|
|
}
|