Improved error notifications

This commit is contained in:
shamoon
2023-08-23 23:50:54 -07:00
parent e6ca6b6f7a
commit cca465aa00
14 changed files with 296 additions and 260 deletions

View File

@@ -398,15 +398,12 @@ describe('DocumentDetailComponent', () => {
const closeSpy = jest.spyOn(component, 'close')
const updateSpy = jest.spyOn(documentService, 'update')
const toastSpy = jest.spyOn(toastService, 'showError')
updateSpy.mockImplementation(() =>
throwError(() => new Error('failed to save'))
)
const error = new Error('failed to save')
updateSpy.mockImplementation(() => throwError(() => error))
component.save()
expect(updateSpy).toHaveBeenCalled()
expect(closeSpy).not.toHaveBeenCalled()
expect(toastSpy).toHaveBeenCalledWith(
'Error saving document: failed to save'
)
expect(toastSpy).toHaveBeenCalledWith('Error saving document', error)
})
it('should show error toast on save but close if user can no longer edit', () => {
@@ -450,15 +447,12 @@ describe('DocumentDetailComponent', () => {
const closeSpy = jest.spyOn(component, 'close')
const updateSpy = jest.spyOn(documentService, 'update')
const toastSpy = jest.spyOn(toastService, 'showError')
updateSpy.mockImplementation(() =>
throwError(() => new Error('failed to save'))
)
const error = new Error('failed to save')
updateSpy.mockImplementation(() => throwError(() => error))
component.saveEditNext()
expect(updateSpy).toHaveBeenCalled()
expect(closeSpy).not.toHaveBeenCalled()
expect(toastSpy).toHaveBeenCalledWith(
'Error saving document: failed to save'
)
expect(toastSpy).toHaveBeenCalledWith('Error saving document', error)
})
it('should show save button and save & close or save & next', () => {
@@ -798,11 +792,7 @@ describe('DocumentDetailComponent', () => {
.mockReturnValue(throwError(() => error))
const toastSpy = jest.spyOn(toastService, 'showError')
initNormally()
expect(toastSpy).toHaveBeenCalledWith(
'Error retrieving metadata',
10000,
error
)
expect(toastSpy).toHaveBeenCalledWith('Error retrieving metadata', error)
})
function initNormally() {

View File

@@ -395,7 +395,6 @@ export class DocumentDetailComponent
this.metadata = null
this.toastService.showError(
$localize`Error retrieving metadata`,
10000,
error
)
},
@@ -417,7 +416,6 @@ export class DocumentDetailComponent
this.suggestions = null
this.toastService.showError(
$localize`Error retrieving suggestions.`,
10000,
error
)
},
@@ -542,11 +540,7 @@ export class DocumentDetailComponent
close && this.close()
} else {
this.error = error.error
this.toastService.showError(
$localize`Error saving document` +
': ' +
(error.error?.detail ?? error.message ?? JSON.stringify(error))
)
this.toastService.showError($localize`Error saving document`, error)
}
},
})
@@ -587,11 +581,7 @@ export class DocumentDetailComponent
error: (error) => {
this.networkActive = false
this.error = error.error
this.toastService.showError(
$localize`Error saving document` +
': ' +
(error.error?.detail ?? error.message ?? JSON.stringify(error))
)
this.toastService.showError($localize`Error saving document`, error)
},
})
}
@@ -640,11 +630,7 @@ export class DocumentDetailComponent
this.close()
},
error: (error) => {
this.toastService.showError(
$localize`Error deleting document: ${
error.error?.detail ?? error.message ?? JSON.stringify(error)
}`
)
this.toastService.showError($localize`Error deleting document`, error)
modal.componentInstance.buttonsEnabled = true
this.subscribeModalDelete(modal)
},
@@ -687,9 +673,8 @@ export class DocumentDetailComponent
modal.componentInstance.buttonsEnabled = true
}
this.toastService.showError(
$localize`Error executing operation: ${JSON.stringify(
error.error
)}`
$localize`Error executing operation`,
error
)
},
})