mirror of
https://github.com/cupcakearmy/cryptgeon.git
synced 2024-12-22 08:16:28 +00:00
feedback on to big error
This commit is contained in:
parent
ba38d2b819
commit
00fd514da5
@ -12,15 +12,23 @@ type CallOptions = {
|
|||||||
body?: any
|
body?: any
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class PayloadToLargeError extends Error {}
|
||||||
|
|
||||||
async function call(options: CallOptions) {
|
async function call(options: CallOptions) {
|
||||||
return fetch('/api/' + options.url, {
|
const response = await fetch('/api/' + options.url, {
|
||||||
method: options.method,
|
method: options.method,
|
||||||
body: options.body === undefined ? undefined : JSON.stringify(options.body),
|
body: options.body === undefined ? undefined : JSON.stringify(options.body),
|
||||||
mode: 'cors',
|
mode: 'cors',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'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) {
|
export async function create(note: Note) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { Note } from '$lib/api'
|
import { Note, PayloadToLargeError } from '$lib/api'
|
||||||
import { create } from '$lib/api'
|
import { create } from '$lib/api'
|
||||||
import { getKeyFromString, encrypt, Hex, getRandomBytes } from '$lib/crypto'
|
import { getKeyFromString, encrypt, Hex, getRandomBytes } from '$lib/crypto'
|
||||||
|
|
||||||
@ -51,8 +51,11 @@
|
|||||||
id: response.id,
|
id: response.id,
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
if (e instanceof PayloadToLargeError) {
|
||||||
error = 'could not create note.'
|
error = 'could not create not. note is to big'
|
||||||
|
} else {
|
||||||
|
error = 'could not create note. please try again.'
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
loading = false
|
loading = false
|
||||||
}
|
}
|
||||||
@ -167,4 +170,8 @@
|
|||||||
.advanced.hidden {
|
.advanced.hidden {
|
||||||
max-height: 0;
|
max-height: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.error-text {
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
Loading…
Reference in New Issue
Block a user