diff --git a/client/src/lib/api.ts b/client/src/lib/api.ts index d8647fe..e884bcf 100644 --- a/client/src/lib/api.ts +++ b/client/src/lib/api.ts @@ -12,15 +12,23 @@ type CallOptions = { body?: any } +export class PayloadToLargeError extends Error {} + async function call(options: CallOptions) { - return fetch('/api/' + options.url, { + const response = await fetch('/api/' + options.url, { method: options.method, body: options.body === undefined ? undefined : JSON.stringify(options.body), mode: 'cors', headers: { 'Content-Type': 'application/json', }, - }).then((r) => r.json()) + }) + + if (!response.ok) { + if (response.status === 413) throw new PayloadToLargeError() + else throw new Error('API call failed') + } + return response.json() } export async function create(note: Note) { diff --git a/client/src/lib/views/Create.svelte b/client/src/lib/views/Create.svelte index 446b6ed..e29d621 100644 --- a/client/src/lib/views/Create.svelte +++ b/client/src/lib/views/Create.svelte @@ -1,5 +1,5 @@