Improving error handling
This commit is contained in:
parent
bf41d27353
commit
5072a69333
5 changed files with 30 additions and 32 deletions
|
@ -24,7 +24,6 @@
|
||||||
border-bottom: solid thin var(--border-color);
|
border-bottom: solid thin var(--border-color);
|
||||||
position: sticky;
|
position: sticky;
|
||||||
top: 0;
|
top: 0;
|
||||||
z-index: 10;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ul {
|
ul {
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
--button-color: #f6f6f6;
|
--button-color: #f6f6f6;
|
||||||
--font-family: -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Cantarell, Ubuntu, roboto, noto, arial, sans-serif;
|
--font-family: -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Cantarell, Ubuntu, roboto, noto, arial, sans-serif;
|
||||||
--navbar-height: 3em;
|
--navbar-height: 3em;
|
||||||
|
--shade-background: rgba(0, 0, 0, 0.2);
|
||||||
--shade-color: #eee;
|
--shade-color: #eee;
|
||||||
--theme-background: white;
|
--theme-background: white;
|
||||||
--theme-color: #444;
|
--theme-color: #444;
|
||||||
|
|
|
@ -13,9 +13,9 @@ export const POST = async ({ params, request }) => {
|
||||||
const capKey = await response.json()
|
const capKey = await response.json()
|
||||||
|
|
||||||
return json({ success: true, capKey })
|
return json({ success: true, capKey })
|
||||||
} catch (err) {
|
} catch (error) {
|
||||||
console.log({ err })
|
console.log({ error })
|
||||||
return json({ success: false, code: 500, error: err })
|
return json({ success: false, code: 500, error })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,12 +25,11 @@ export const POST = async ({ params, request }) => {
|
||||||
const url = `${env.TAHOE_API}/uri/${encodedCapKey}?t=json`
|
const url = `${env.TAHOE_API}/uri/${encodedCapKey}?t=json`
|
||||||
const response = await fetch(url, { method: 'GET' })
|
const response = await fetch(url, { method: 'GET' })
|
||||||
const list = await response.json()
|
const list = await response.json()
|
||||||
console.log({ url, list })
|
|
||||||
|
|
||||||
return json({ success: true, list })
|
return json({ success: true, list })
|
||||||
} catch (err) {
|
} catch (error) {
|
||||||
console.log({ err })
|
console.log({ error })
|
||||||
return json({ success: false, code: 500, error: err })
|
return json({ success: false, code: 500, error, message: error.cause.message })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,14 @@ export const actions = {
|
||||||
body: JSON.stringify({ capKey: encoded })
|
body: JSON.stringify({ capKey: encoded })
|
||||||
})
|
})
|
||||||
const jsonResponse = await response.json()
|
const jsonResponse = await response.json()
|
||||||
if (!jsonResponse.success) throw new Error(jsonResponse.error)
|
|
||||||
|
if (!jsonResponse.success) {
|
||||||
|
if (jsonResponse.message.includes('ECONNREFUSED')) {
|
||||||
|
return { error: 'Tahoe server may be offline.' }
|
||||||
|
} else {
|
||||||
|
throw new Error(jsonResponse.error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return { endpoint: 'listDirectories', list: jsonResponse.list, capKey }
|
return { endpoint: 'listDirectories', list: jsonResponse.list, capKey }
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
let capKey = $state()
|
let capKey = $state()
|
||||||
let capKeyInput = $state()
|
let capKeyInput = $state()
|
||||||
let newCapKey = $state()
|
let newCapKey = $state()
|
||||||
|
let modalTitle = $state()
|
||||||
|
let modalText = $state()
|
||||||
let checked = $state(false)
|
let checked = $state(false)
|
||||||
let showModal = $state(false)
|
let showModal = $state(false)
|
||||||
|
|
||||||
|
@ -39,7 +41,9 @@
|
||||||
beforeNavigate(({ cancel }) => {
|
beforeNavigate(({ cancel }) => {
|
||||||
if (newCapKey && !capKey) {
|
if (newCapKey && !capKey) {
|
||||||
cancel()
|
cancel()
|
||||||
alert('Please confirm you copied and saved the cap key.')
|
modalTitle = 'Warning'
|
||||||
|
modalText = 'Please confirm you copied and saved the cap key.'
|
||||||
|
showModal = true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -48,6 +52,14 @@
|
||||||
})
|
})
|
||||||
|
|
||||||
$effect(() => console.log({ form }))
|
$effect(() => console.log({ form }))
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (form?.error) {
|
||||||
|
modalTitle = 'Error'
|
||||||
|
modalText = form.error
|
||||||
|
showModal = true
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
|
@ -56,8 +68,6 @@
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
<h1>Dashboard</h1>
|
<h1>Dashboard</h1>
|
||||||
|
|
||||||
<button onclick={() => showModal = true}>Modal</button>
|
|
||||||
|
|
||||||
{#if !capKey && !newCapKey}
|
{#if !capKey && !newCapKey}
|
||||||
<div class='cap-key-div add'>
|
<div class='cap-key-div add'>
|
||||||
<form action='?/listDirectories' method='post' enctype='form-data' use:enhance={enhanceForm}>
|
<form action='?/listDirectories' method='post' enctype='form-data' use:enhance={enhanceForm}>
|
||||||
|
@ -112,7 +122,8 @@
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<Modal {showModal} escape={() => showModal = false}>
|
<Modal {showModal} escape={() => showModal = false}>
|
||||||
<h1>Modal</h1>
|
<h2>{modalTitle}</h2>
|
||||||
|
<p>{modalText}</p>
|
||||||
<button onclick={() => showModal = false}>Ok</button>
|
<button onclick={() => showModal = false}>Ok</button>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
|
@ -131,25 +142,6 @@
|
||||||
margin: 1em 0;
|
margin: 1em 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.cap-key {
|
|
||||||
display: flex;
|
|
||||||
margin: auto 0 2em 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.cap-key label {
|
|
||||||
min-width: 5em;
|
|
||||||
margin: auto 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.cap-key input {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.cap-key button {
|
|
||||||
min-width: 10em;
|
|
||||||
margin: auto 0 auto 1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.cap-key-div {
|
.cap-key-div {
|
||||||
max-width: 45em;
|
max-width: 45em;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue