mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
Fix: catch sessionStorage errors for large documents (#6150)
This commit is contained in:
@@ -5,10 +5,11 @@ import {
|
||||
HttpTestingController,
|
||||
} from '@angular/common/http/testing'
|
||||
import { environment } from 'src/environments/environment'
|
||||
import { Subscription } from 'rxjs'
|
||||
import { Subscription, throwError } from 'rxjs'
|
||||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
|
||||
import { ConfirmDialogComponent } from '../components/common/confirm-dialog/confirm-dialog.component'
|
||||
import { OPEN_DOCUMENT_SERVICE } from '../data/storage-keys'
|
||||
import { wind } from 'ngx-bootstrap-icons'
|
||||
|
||||
const documents = [
|
||||
{
|
||||
@@ -233,4 +234,12 @@ describe('OpenDocumentsService', () => {
|
||||
req.error(new ErrorEvent('timeout'))
|
||||
expect(openDocumentsService.getOpenDocuments()).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('should log error on sessionStorage save', () => {
|
||||
const doc = { ...documents[0] }
|
||||
doc.content = 'a'.repeat(1000000)
|
||||
const consoleSpy = jest.spyOn(console, 'error').mockImplementation()
|
||||
openDocumentsService.openDocument(doc)
|
||||
expect(consoleSpy).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
@@ -152,9 +152,13 @@ export class OpenDocumentsService {
|
||||
}
|
||||
|
||||
save() {
|
||||
sessionStorage.setItem(
|
||||
OPEN_DOCUMENT_SERVICE.DOCUMENTS,
|
||||
JSON.stringify(this.openDocuments)
|
||||
)
|
||||
try {
|
||||
sessionStorage.setItem(
|
||||
OPEN_DOCUMENT_SERVICE.DOCUMENTS,
|
||||
JSON.stringify(this.openDocuments)
|
||||
)
|
||||
} catch (e) {
|
||||
console.error('Error saving open documents to session storage', e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user