Skip to content

Commit 62d5b15

Browse files
committed
enhance: error handling and improve configuration inspection
1 parent 0dac778 commit 62d5b15

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

app/src/views/config/InspectConfig.vue

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
<script setup lang="ts">
2+
import type { CosyError } from '@/lib/http/types'
23
import ngx from '@/api/ngx'
4+
import { translateError } from '@/lib/http/error'
35
import { logLevel } from '@/views/config/constants'
46
57
defineProps<{
68
banner?: boolean
79
}>()
810
9-
const data = ref({
10-
level: 0,
11-
message: '',
12-
})
11+
interface TestResult extends CosyError {
12+
message: string
13+
level: number
14+
}
15+
16+
const data = ref<TestResult>()
17+
const translatedError = ref<string>('')
1318
1419
test()
1520
1621
function test() {
1722
ngx.test().then(r => {
1823
data.value = r
24+
if (r && r.level > logLevel.Warn) {
25+
const cosyError: CosyError = {
26+
...r,
27+
}
28+
translateError(cosyError).then(translated => {
29+
translatedError.value = translated
30+
})
31+
}
1932
})
2033
}
2134
@@ -27,7 +40,7 @@ defineExpose({
2740
<template>
2841
<div class="inspect-container">
2942
<AAlert
30-
v-if="data?.level <= logLevel.Info"
43+
v-if="data && data.level <= logLevel.Info"
3144
:banner
3245
:message="$gettext('Configuration file is test successful')"
3346
type="success"
@@ -41,19 +54,19 @@ defineExpose({
4154
show-icon
4255
>
4356
<template #description>
44-
{{ data.message }}
57+
{{ data?.message }}
4558
</template>
4659
</AAlert>
4760

4861
<AAlert
49-
v-else-if="data?.level > logLevel.Warn"
62+
v-else-if="data && data.level > logLevel.Warn"
5063
:message="$gettext('Error')"
5164
:banner
5265
type="error"
5366
show-icon
5467
>
5568
<template #description>
56-
{{ data.message }}
69+
{{ translatedError }}
5770
</template>
5871
</AAlert>
5972
</div>

app/src/views/site/site_edit/components/SiteEditor/store.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import type { CertificateInfo } from '@/api/cert'
22
import type { Site } from '@/api/site'
3+
import type { CosyError } from '@/lib/http/types'
34
import type { CheckedType } from '@/types'
45
import config from '@/api/config'
56
import ngx from '@/api/ngx'
67
import site from '@/api/site'
78
import { useNgxConfigStore } from '@/components/NgxConfigEditor'
9+
import { translateError } from '@/lib/http/error'
810

911
export const useSiteEditorStore = defineStore('siteEditor', () => {
1012
const advanceMode = ref(false)
@@ -46,7 +48,7 @@ export const useSiteEditorStore = defineStore('siteEditor', () => {
4648
handleResponse(r)
4749
}
4850
catch (error) {
49-
handleParseError(error as { error?: string, message: string })
51+
handleParseError(error as CosyError)
5052
}
5153
}
5254
loading.value = false
@@ -77,17 +79,17 @@ export const useSiteEditorStore = defineStore('siteEditor', () => {
7779
handleResponse(response)
7880
}
7981
catch (error) {
80-
handleParseError(error as { error?: string, message: string })
82+
handleParseError(error as CosyError)
8183
}
8284
finally {
8385
saving.value = false
8486
}
8587
}
8688

87-
function handleParseError(e: { error?: string, message: string }) {
89+
async function handleParseError(e: CosyError) {
8890
console.error(e)
8991
parseErrorStatus.value = true
90-
parseErrorMessage.value = e.message
92+
parseErrorMessage.value = await translateError(e)
9193
config.getItem(`sites-available/${encodeURIComponent(name.value)}`).then(r => {
9294
configText.value = r.content
9395
})

0 commit comments

Comments
 (0)