refactored more error code

This commit is contained in:
2025-09-26 21:10:19 +02:00
parent e3b735bb7b
commit 2463f92b1c
23 changed files with 111 additions and 173 deletions

View File

@@ -2,14 +2,14 @@
import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router';
import { api } from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js';
import { api } from '../../urls.svelte';
import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte';
import ContactSelector from '../../Components/ContactSelector.svelte';
let company = $state(null);
let docType = $state(null);
let error = $state(null);
let router = useTinyRouter();
let document = $state({
@@ -36,7 +36,7 @@
if (company.bank_account) document.sender.bank_account = company.bank_account;
if (company.court) document.sender.court = company.court;
} else {
error = await resp.text();
error(resp);
}
}
@@ -47,11 +47,12 @@
const types = await resp.json();
docType = t('type_'+types[document.type]);
} else {
error = await resp.text();
error(resp);
}
}
function load(){
yikes();
loadCompanies();
loadDocType();
}
@@ -83,7 +84,7 @@
const json = await resp.json();
router.navigate(`/document/${json.id}/view`);
} else {
error = await resp.text();
error(resp);
}
}
@@ -95,9 +96,6 @@
</style>
<fieldset>
{#if error}
<span class="error">{error}</span>
{/if}
{#if docType}
<legend>{t('add_object',{object:docType})}</legend>
{/if}

View File

@@ -2,6 +2,7 @@
import { onMount } from 'svelte';
import { api } from '../../urls.svelte.js';
import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte.js';
import EstimatedTask from '../../Components/EstimatedTask.svelte';
@@ -11,7 +12,6 @@
onSelect = (task) => {}
} = $props();
let error = $state(null);
let projects = $state(null);
async function loadItems(){
@@ -24,8 +24,9 @@
});
if (resp.ok){
projects = await resp.json();
yikes();
} else {
error = await resp.body();
error(resp);
}
}
@@ -43,9 +44,6 @@
<div>
<h1>{t('estimated_times')}</h1>
{#if error}
<span class="error">{error}</span>
{/if}
{#if projects}
{#each projects as project,pid}
<fieldset>

View File

@@ -2,6 +2,7 @@
import { onMount } from 'svelte';
import { api } from '../../urls.svelte.js';
import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte.js';
import Item from '../../Components/Item.svelte';
@@ -12,8 +13,6 @@
} = $props();
let items = $state(null);
let error = $state(null);
async function loadItems(){
const url = api('items/list');
@@ -25,8 +24,9 @@
});
if (resp.ok){
items = await resp.json();
yikes();
} else {
error = await resp.body();
error(resp);
}
}
@@ -36,9 +36,6 @@
<div>
<h1>{t('items')}</h1>
{#if error}
<span class="error">{error}</span>
{/if}
{#if items}
{#each items as item,id}
<Item item={item} onclick={() => onSelect(item)} />

View File

@@ -3,11 +3,11 @@
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 TypeSelector from './TypeSelector.svelte';
let error = null;
let companies = {};
let router = useTinyRouter();
let company_id = +router.query.company_id;
@@ -28,7 +28,7 @@
if (resp.ok){
load(selected_company); // relaod docs
} else {
error = await resp.text();
error(resp);
}
}
}
@@ -45,7 +45,7 @@
if (resp.ok){
documents = await resp.json();
} else {
error = await resp.text();
error(resp);
}
}
@@ -54,8 +54,9 @@
const resp = await fetch(url,{ credentials: 'include'});
if (resp.ok){
companies = await resp.json();
yikes();
} else {
error = await resp.text();
error(resp);
}
if (company_id) {
for (let comp of Object.values(companies)){

View File

@@ -3,13 +3,13 @@
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 Position from './Position.svelte';
var {
document = $bindable(null),
error = $bindable(null),
submit = (key,newVal) => {},
} = $props();
@@ -18,7 +18,6 @@
async function updatePositions(resp){
let json = await resp.json();
document.positions = {};
error = null;
setTimeout(() => document.positions = json,100)
}
@@ -32,7 +31,7 @@
if (resp.ok){
updatePositions(resp);
} else {
error = await resp.text();
error(resp);
}
}
@@ -48,7 +47,7 @@
if (resp.ok){
updatePositions(resp);
} else {
error = await resp.text();
error(resp);
}
}
</script>

View File

@@ -3,12 +3,12 @@
import { useTinyRouter } from 'svelte-tiny-router';
import { api } from '../../urls.svelte.js';
import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte.js';
let content = $state(null);
let doc = $state(null);
let email = $state(null);
let error = $state(null);
const router = useTinyRouter();
let subject = $state(null);
let { id } = $props();
@@ -20,9 +20,9 @@
doc = await resp.json();
email = doc.customer.email;
subject = t('new_document_from',{type:t(doc.type),sender:doc.company.name,number:doc.number}),
error = null;
yikes();
} else {
error = await resp.text();
error(resp);
return;
}
url = api(`document/${id}/settings`);
@@ -31,7 +31,7 @@
const settings = await resp.json();
content = settings.content;
} else {
error = await resp.text();
error(resp);
}
}
@@ -46,17 +46,13 @@
if (resp.ok){
router.navigate(`/document?company_id=${doc.company.id}`);
} else {
error = await resp.text();
error(resp);
}
}
onMount(loadDoc);
</script>
{#if error}
<span class="error">{error}</span>
{/if}
<fieldset>
<legend>{t('customer_email')} / {t('subject')}</legend>
<input type="text" bind:value={email} />

View File

@@ -2,6 +2,7 @@
import { onMount } from 'svelte';
import { api, target } from '../../urls.svelte.js';
import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte.js';
let {
@@ -9,7 +10,6 @@
onSelect = (time) => {}
} = $props();
let error = $state(null);
let projects = $state(null);
let times = $state(null);
@@ -23,8 +23,9 @@
});
if (resp.ok){
projects = await resp.json();
yikes();
} else {
error = await resp.body();
error(resp);
}
}
@@ -39,7 +40,7 @@
if (resp.ok){
times = await resp.json();
} else {
error = await resp.body();
error(resp);
}
}

View File

@@ -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>