mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Properly display api errors on list filter & translate error message
This commit is contained in:
		| @@ -100,7 +100,7 @@ | |||||||
| <ng-container *ngTemplateOutlet="pagination"></ng-container> | <ng-container *ngTemplateOutlet="pagination"></ng-container> | ||||||
|  |  | ||||||
| <ng-container *ngIf="list.error ; else documentListNoError"> | <ng-container *ngIf="list.error ; else documentListNoError"> | ||||||
|   <div class="alert alert-danger" role="alert">Error while loading documents: {{list.error}}</div> |   <div class="alert alert-danger" role="alert"><ng-container i18n>Error while loading documents</ng-container>: {{list.error}}</div> | ||||||
| </ng-container> | </ng-container> | ||||||
|  |  | ||||||
| <ng-template #documentListNoError> | <ng-template #documentListNoError> | ||||||
|   | |||||||
| @@ -9,7 +9,7 @@ import { | |||||||
| import { PaperlessDocument } from '../data/paperless-document' | import { PaperlessDocument } from '../data/paperless-document' | ||||||
| import { PaperlessSavedView } from '../data/paperless-saved-view' | import { PaperlessSavedView } from '../data/paperless-saved-view' | ||||||
| import { DOCUMENT_LIST_SERVICE } from '../data/storage-keys' | 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' | import { SettingsService, SETTINGS_KEYS } from './settings.service' | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -160,7 +160,21 @@ export class DocumentListViewService { | |||||||
|             activeListViewState.currentPage = 1 |             activeListViewState.currentPage = 1 | ||||||
|             this.reload() |             this.reload() | ||||||
|           } else { |           } else { | ||||||
|             this.error = error.error |             let errorMessage | ||||||
|  |             if (Object.keys(error.error).length > 0) { | ||||||
|  |               // e.g. { archive_serial_number: Array<string> } | ||||||
|  |               errorMessage = Object.keys(error.error) | ||||||
|  |                 .map((fieldName) => { | ||||||
|  |                   const fieldError: Array<string> = error.error[fieldName] | ||||||
|  |                   return `${ | ||||||
|  |                     DOCUMENT_SORT_FIELDS.find((f) => f.field == fieldName)?.name | ||||||
|  |                   }: ${fieldError[0]}` | ||||||
|  |                 }) | ||||||
|  |                 .join(', ') | ||||||
|  |             } else { | ||||||
|  |               errorMessage = error.error | ||||||
|  |             } | ||||||
|  |             this.error = errorMessage | ||||||
|           } |           } | ||||||
|         }, |         }, | ||||||
|       }) |       }) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Michael Shamoon
					Michael Shamoon