From 199fc6be94d94c8460cd5689dbfe92c43d20e45d Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Sat, 2 Apr 2022 17:05:15 -0700 Subject: [PATCH 1/2] Properly display api errors on list filter & translate error message --- .../document-list/document-list.component.html | 2 +- .../app/services/document-list-view.service.ts | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src-ui/src/app/components/document-list/document-list.component.html b/src-ui/src/app/components/document-list/document-list.component.html index 9c3696aae..c7d53a848 100644 --- a/src-ui/src/app/components/document-list/document-list.component.html +++ b/src-ui/src/app/components/document-list/document-list.component.html @@ -100,7 +100,7 @@ - Error while loading documents: {{list.error}} + Error while loading documents: {{list.error}} diff --git a/src-ui/src/app/services/document-list-view.service.ts b/src-ui/src/app/services/document-list-view.service.ts index fa07649af..e67ceda4b 100644 --- a/src-ui/src/app/services/document-list-view.service.ts +++ b/src-ui/src/app/services/document-list-view.service.ts @@ -9,7 +9,7 @@ import { import { PaperlessDocument } from '../data/paperless-document' import { PaperlessSavedView } from '../data/paperless-saved-view' import { DOCUMENT_LIST_SERVICE } from '../data/storage-keys' -import { DocumentService } from './rest/document.service' +import { DocumentService, DOCUMENT_SORT_FIELDS } from './rest/document.service' import { SettingsService, SETTINGS_KEYS } from './settings.service' /** @@ -160,7 +160,21 @@ export class DocumentListViewService { activeListViewState.currentPage = 1 this.reload() } else { - this.error = error.error + let errorMessage + if (Object.keys(error.error).length > 0) { + // e.g. { archive_serial_number: Array } + errorMessage = Object.keys(error.error) + .map((fieldName) => { + const fieldError: Array = error.error[fieldName] + return `${ + DOCUMENT_SORT_FIELDS.find((f) => f.field == fieldName)?.name + }: ${fieldError[0]}` + }) + .join(', ') + } else { + errorMessage = error.error + } + this.error = errorMessage } }, }) From 19d5feb483550c090ec4e9d58f45c00f6ff35626 Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri, 1 Apr 2022 21:50:53 -0700 Subject: [PATCH 2/2] Fix save view error for filter_rules see #601 --- .../components/document-list/document-list.component.ts | 8 ++++++-- .../save-view-config-dialog.component.html | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src-ui/src/app/components/document-list/document-list.component.ts b/src-ui/src/app/components/document-list/document-list.component.ts index fac5e3535..9e058fb64 100644 --- a/src-ui/src/app/components/document-list/document-list.component.ts +++ b/src-ui/src/app/components/document-list/document-list.component.ts @@ -243,8 +243,12 @@ export class DocumentListComponent implements OnInit, OnDestroy, AfterViewInit { $localize`View "${savedView.name}" created successfully.` ) }, - error: (error) => { - modal.componentInstance.error = error.error + error: (httpError) => { + let error = httpError.error + if (error.filter_rules) { + error.filter_rules = error.filter_rules.map((r) => r.value) + } + modal.componentInstance.error = error modal.componentInstance.buttonsEnabled = true }, }) diff --git a/src-ui/src/app/components/document-list/save-view-config-dialog/save-view-config-dialog.component.html b/src-ui/src/app/components/document-list/save-view-config-dialog/save-view-config-dialog.component.html index d03588589..ae20031a2 100644 --- a/src-ui/src/app/components/document-list/save-view-config-dialog/save-view-config-dialog.component.html +++ b/src-ui/src/app/components/document-list/save-view-config-dialog/save-view-config-dialog.component.html @@ -8,6 +8,11 @@ + + Filter rules error occurred while saving this view + The error returned was: + {{ error.filter_rules }} +