refac
This commit is contained in:
1 parent
84b1ab0ed3
commit
622767d724
17 files changed
+192
-164
No files matched your search
@@ -1,29 +1,48 @@
|
||||
<script lang="ts">
|
||||
import Info from '$lib/components/icons/Info.svelte';
|
||||
|
||||
export let content = '';
|
||||
export let content: unknown = '';
|
||||
|
||||
const getErrorMessage = (value: unknown): string => {
|
||||
if (typeof value === 'string') {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (typeof value === 'object' && value !== null) {
|
||||
const error = 'error' in value ? value.error : null;
|
||||
|
||||
if (
|
||||
typeof error === 'object' &&
|
||||
error !== null &&
|
||||
'message' in error &&
|
||||
typeof error.message === 'string'
|
||||
) {
|
||||
return error.message;
|
||||
}
|
||||
|
||||
if ('detail' in value && typeof value.detail === 'string') {
|
||||
return value.detail;
|
||||
}
|
||||
|
||||
if ('message' in value && typeof value.message === 'string') {
|
||||
return value.message;
|
||||
}
|
||||
|
||||
return JSON.stringify(value) ?? String(value);
|
||||
}
|
||||
|
||||
return JSON.stringify(value) ?? String(value);
|
||||
};
|
||||
|
||||
$: message = getErrorMessage(content) || 'Error submitting message';
|
||||
</script>
|
||||
|
||||
<div class="flex my-2 gap-2.5 border px-4 py-3 border-red-600/10 bg-red-600/10 rounded-lg">
|
||||
<div class=" self-start mt-0.5">
|
||||
<Info className="size-5 text-red-700 dark:text-red-400" />
|
||||
</div>
|
||||
<div
|
||||
class="my-2 flex w-full items-center gap-3 rounded-3xl bg-gray-100 px-4 py-3 text-gray-800 dark:bg-gray-800 dark:text-gray-100"
|
||||
>
|
||||
<Info className="size-5 shrink-0" strokeWidth="2" />
|
||||
|
||||
<div class=" self-center text-sm">
|
||||
{#if typeof content === 'string'}
|
||||
{content}
|
||||
{:else if typeof content === 'object' && content !== null}
|
||||
{#if content?.error && content?.error?.message}
|
||||
{content.error.message}
|
||||
{:else if content?.detail}
|
||||
{content.detail}
|
||||
{:else if content?.message}
|
||||
{content.message}
|
||||
{:else}
|
||||
{JSON.stringify(content)}
|
||||
{/if}
|
||||
{:else}
|
||||
{JSON.stringify(content)}
|
||||
{/if}
|
||||
<div class="min-w-0 self-center break-words text-sm">
|
||||
{message}
|
||||
</div>
|
||||
</div>
|
||||
@@ -104,7 +104,7 @@
|
||||
aria-label={$showSidebar ? $i18n.t('Close Sidebar') : $i18n.t('Open Sidebar')}
|
||||
>
|
||||
<div class="self-center p-1.5">
|
||||
<Sidebar />
|
||||
<Sidebar className="size-4" />
|
||||
</div>
|
||||
</button>
|
||||
</Tooltip>
|
||||
|
||||
Reference in new issue
Block a user