Skip to content

Commit

Permalink
优化错误提示
Browse files Browse the repository at this point in the history
  • Loading branch information
jianyun8023 committed Aug 22, 2024
1 parent 57c2cb3 commit e8b4001
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
42 changes: 31 additions & 11 deletions app/calibre-pages/src/views/Setting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
size="default"
@click="scope.row.func(scope.row)"
>
{{scope.row.operator}}
{{ scope.row.operator }}
</el-button>
</template>
</el-table-column>
Expand Down Expand Up @@ -70,11 +70,22 @@ export default {
config.loading = false
if (response.ok) {
const responseData = await response.json()
ElNotification({
title: 'Index switched successfully.',
message: h('i', {style: 'color: teal'}, 'Index switched successfully.'),
type: 'success'
})
if (responseData.code === 200) {
ElNotification({
title: 'Index switched successfully.',
message: h('i', {style: 'color: teal'}, 'Index switched successfully.'),
type: 'success'
})
} else {
ElNotification({
title: 'Failed to update index.',
message: h('i', {style: 'color: red'}, 'Error: ' + responseData.error),
type: 'error'
})
}
} else {
ElNotification({
title: 'Failed to update index.',
Expand All @@ -98,11 +109,20 @@ export default {
config.loading = false
if (response.ok) {
const responseData = await response.json()
ElNotification({
title: 'Index updated successfully.',
message: h('i', {style: 'color: teal'}, 'Index updated successfully.'),
type: 'success'
})
if (responseData.code === 200) {
ElNotification({
title: 'Index update successfully.',
message: h('i', {style: 'color: teal'}, 'Index updated successfully.'),
type: 'success'
})
} else {
ElNotification({
title: 'Failed to update index.',
message: h('i', {style: 'color: red'}, 'Error: ' + responseData.error),
type: 'error'
})
}
} else {
ElNotification({
title: 'Failed to update index.',
Expand Down
18 changes: 9 additions & 9 deletions internal/calibre/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,12 @@ func (c Api) switchIndex(c2 *gin.Context) {
})
if err != nil {
log.Warn(err)
c2.JSON(http.StatusInternalServerError, gin.H{"code": 500, "error": err.Error()})
c2.JSON(http.StatusOK, gin.H{"code": 500, "error": err.Error()})
return
}
if len(resp.Results) != 0 {
log.Warn(err)
c2.JSON(http.StatusInternalServerError, gin.H{"code": 400, "error": "有任务正在执行,请稍后再试"})
c2.JSON(http.StatusOK, gin.H{"code": 400, "error": "有任务正在执行,请稍后再试"})
return
}

Expand All @@ -371,7 +371,7 @@ func (c Api) switchIndex(c2 *gin.Context) {
)
if err != nil {
log.Warn(err)
c2.JSON(http.StatusInternalServerError, gin.H{"code": 500, "error": err.Error()})
c2.JSON(http.StatusOK, gin.H{"code": 500, "error": err.Error()})
return
}
c2.JSON(http.StatusOK, gin.H{
Expand All @@ -383,15 +383,15 @@ func (c Api) updateIndex(c2 *gin.Context) {
booksIds, err2 := c.contentApi.GetAllBooksIds()
if err2 != nil {
log.Warn(err2)
c2.JSON(http.StatusInternalServerError, gin.H{"code": 500, "error": err2.Error()})
c2.JSON(http.StatusOK, gin.H{"code": 500, "error": err2.Error()})
return
}

index := c.client.Index(c.config.Search.Index + "-bak")
_, err := index.DeleteAllDocuments()
if err != nil {
log.Warn(err)
c2.JSON(http.StatusInternalServerError, gin.H{"code": 500, "error": err.Error()})
c2.JSON(http.StatusOK, gin.H{"code": 500, "error": err.Error()})
return
}

Expand All @@ -405,17 +405,17 @@ func (c Api) updateIndex(c2 *gin.Context) {
data, err := c.contentApi.GetBookMetaDatas(ids, "")
if err != nil {
log.Warnf("get book metadata error: %v", err)
c2.JSON(http.StatusInternalServerError, gin.H{"code": 500, "error": err.Error()})
c2.JSON(http.StatusOK, gin.H{"code": 500, "error": "get book metadata error: " + err.Error()})
return
}
books, err = convertContentBooks(data)
if err != nil {
c2.JSON(http.StatusInternalServerError, gin.H{"code": 500, "error": err.Error()})
c2.JSON(http.StatusOK, gin.H{"code": 500, "error": err.Error()})
return
}
task, err := index.AddDocumentsInBatches(books, len(ids))
if err != nil {
c2.JSON(http.StatusInternalServerError, gin.H{"code": 500, "error": err.Error()})
c2.JSON(http.StatusOK, gin.H{"code": 500, "error": err.Error()})
return
}
for _, info := range task {
Expand All @@ -425,7 +425,7 @@ func (c Api) updateIndex(c2 *gin.Context) {

err = waitForTask(c, taskIds)
if err != nil {
c2.JSON(http.StatusInternalServerError, gin.H{"code": 500, "error": err.Error()})
c2.JSON(http.StatusOK, gin.H{"code": 500, "error": err.Error()})
return
}

Expand Down

0 comments on commit e8b4001

Please sign in to comment.