refactored more error code
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import { useTinyRouter } from 'svelte-tiny-router';
|
||||
|
||||
import {api} from '../../urls.svelte.js';
|
||||
import { error, yikes } from '../../warn.svelte';
|
||||
import { t } from '../../translations.svelte.js';
|
||||
import { user } from '../../user.svelte.js';
|
||||
|
||||
@@ -20,7 +21,6 @@
|
||||
|
||||
let doc = $state(null);
|
||||
let editable = $derived(doc.state == 1);
|
||||
let error = $state(null);
|
||||
let { id } = $props();
|
||||
let pdfDisabled = $state(false);
|
||||
let position_select = $state(false);
|
||||
@@ -36,9 +36,9 @@
|
||||
});
|
||||
if (resp.ok){
|
||||
doc.positions = await resp.json();
|
||||
error = null;
|
||||
yikes();
|
||||
} else {
|
||||
error = await resp.text();
|
||||
error(resp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,12 +64,12 @@
|
||||
body : type
|
||||
});
|
||||
if (res.ok) {
|
||||
error = null;
|
||||
yikes();
|
||||
let json = await res.json();
|
||||
router.navigate(`/document/${json.id}/view`);
|
||||
loadDoc();
|
||||
} else {
|
||||
error = await res.text();
|
||||
error(res);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,9 +78,9 @@
|
||||
const resp = await fetch(url,{credentials:'include'});
|
||||
if (resp.ok){
|
||||
doc = await resp.json();
|
||||
error = null;
|
||||
yikes();
|
||||
} else {
|
||||
error = await resp.text();
|
||||
error(resp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@
|
||||
const url = api(`document/${doc.id}/pdf`);
|
||||
const resp = await fetch(url,{credentials:'include'});
|
||||
if (resp.ok){
|
||||
error = null;
|
||||
yikes();
|
||||
const blob = await resp.blob();
|
||||
const parts = resp.headers.get("Content-disposition").split(";");
|
||||
const filename = parts[1].split('=')[1].split('"').join('');
|
||||
@@ -99,7 +99,7 @@
|
||||
fileLink.download = filename;
|
||||
fileLink.click();
|
||||
} else {
|
||||
error = await resp.text();
|
||||
error(resp);
|
||||
}
|
||||
pdfDisabled = false;
|
||||
}
|
||||
@@ -133,10 +133,6 @@
|
||||
<title>Umbrella – {t('document')} {doc?.number}</title>
|
||||
</svelte:head>
|
||||
|
||||
{#if error}
|
||||
<span class="error">{error}</span>
|
||||
{/if}
|
||||
|
||||
{#if doc}
|
||||
<fieldset class="customer">
|
||||
<legend>{t('customer')}</legend>
|
||||
@@ -248,7 +244,7 @@
|
||||
<button onclick={() => position_select = true}>{t('add_object',{object:t('position')})}</button>
|
||||
{/if}
|
||||
</legend>
|
||||
<PositionList bind:document={doc} submit={update} bind:error={error} />
|
||||
<PositionList bind:document={doc} submit={update} />
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>{t('footer')}</legend>
|
||||
|
||||
Reference in New Issue
Block a user