mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-09-16 21:55:37 -05:00
Better handle cf sorting errors
This commit is contained in:
@@ -156,7 +156,7 @@ describe('DocumentListViewService', () => {
|
||||
expect(documentListViewService.currentPage).toEqual(1)
|
||||
})
|
||||
|
||||
it('should handle error on filtering request', () => {
|
||||
it('should handle object error on filtering request', () => {
|
||||
documentListViewService.currentPage = 1
|
||||
const tags__id__in = 'hello'
|
||||
const filterRulesAny = [
|
||||
@@ -185,6 +185,50 @@ describe('DocumentListViewService', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('should handle object error on filtering request for custom field sorts', () => {
|
||||
documentListViewService.currentPage = 1
|
||||
documentListViewService.sortField = 'custom_field_999'
|
||||
let req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}documents/?page=1&page_size=50&ordering=-custom_field_999&truncate_content=true`
|
||||
)
|
||||
expect(req.request.method).toEqual('GET')
|
||||
req.flush(
|
||||
{ custom_field_999: ['Custom field not found'] },
|
||||
{ status: 400, statusText: 'Unexpected error' }
|
||||
)
|
||||
expect(documentListViewService.error).toEqual(
|
||||
'custom_field_999: Custom field not found'
|
||||
)
|
||||
// reset the list
|
||||
documentListViewService.sortField = 'created'
|
||||
req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}documents/?page=1&page_size=50&ordering=-created&truncate_content=true`
|
||||
)
|
||||
})
|
||||
|
||||
it('should handle string error on filtering request', () => {
|
||||
documentListViewService.currentPage = 1
|
||||
const tags__id__in = 'hello'
|
||||
const filterRulesAny = [
|
||||
{
|
||||
rule_type: FILTER_HAS_TAGS_ANY,
|
||||
value: tags__id__in,
|
||||
},
|
||||
]
|
||||
documentListViewService.filterRules = filterRulesAny
|
||||
let req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}documents/?page=1&page_size=50&ordering=-created&truncate_content=true&tags__id__in=${tags__id__in}`
|
||||
)
|
||||
expect(req.request.method).toEqual('GET')
|
||||
req.flush('Generic error', { status: 404, statusText: 'Unexpected error' })
|
||||
expect(documentListViewService.error).toEqual('Generic error')
|
||||
// reset the list
|
||||
documentListViewService.filterRules = []
|
||||
req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}documents/?page=1&page_size=50&ordering=-created&truncate_content=true`
|
||||
)
|
||||
})
|
||||
|
||||
it('should support setting sort', () => {
|
||||
expect(documentListViewService.sortField).toEqual('created')
|
||||
expect(documentListViewService.sortReverse).toBeTruthy()
|
||||
|
@@ -307,18 +307,23 @@ export class DocumentListViewService {
|
||||
activeListViewState.currentPage = 1
|
||||
this.reload()
|
||||
} else {
|
||||
console.log(error)
|
||||
|
||||
this.selectionData = null
|
||||
let errorMessage
|
||||
if (
|
||||
typeof error.error !== 'string' &&
|
||||
typeof error.error === 'object' &&
|
||||
Object.keys(error.error).length > 0
|
||||
) {
|
||||
// e.g. { archive_serial_number: Array<string> }
|
||||
errorMessage = Object.keys(error.error)
|
||||
.map((fieldName) => {
|
||||
const fieldNameBase = fieldName.split('__')[0]
|
||||
const fieldError: Array<string> = error.error[fieldName]
|
||||
return `${
|
||||
this.sortFields.find((f) => f.field == fieldName)?.name
|
||||
this.sortFields.find(
|
||||
(f) => f.field?.split('__')[0] == fieldNameBase
|
||||
)?.name ?? fieldNameBase
|
||||
}: ${fieldError[0]}`
|
||||
})
|
||||
.join(', ')
|
||||
|
Reference in New Issue
Block a user