Errors guide
May 25, 2023 ยท View on GitHub
As usual, it is better to catch any potential error:
this.storage.set('color', 'red').subscribe({
next: () => {},
error: (error) => {},
});
For read operations, you can also manage errors by providing a default value:
import { catchError, of } from 'rxjs';
this.storage.get('color').pipe(
catchError(() => of('red')),
).subscribe((result) => {});
Could happen to anyone:
.set(): storage is full (DOMExceptionwith nameQuotaExceededError).set(): value is too big (DOMExceptionwith nameUnknownError), for example Chromium-based browsers have a 133169152 bytes limit
Could only happen when in localStorage fallback:
.set(): error in JSON serialization because of circular references (TypeError).set(): trying to store data that cannot be serialized likeBlob,MaporSet(SerializationErrorfrom this lib).get(): error in JSON unserialization (SyntaxError)
Should only happen if data was corrupted or modified from outside of the lib:
.get(): data invalid against your JSON schema (ValidationErrorfrom this lib)- any method when in
indexedDB: database store has been deleted (DOMExceptionwith nameNotFoundError)
Could only happen when in Safari private mode:
.set(): trying to store aBlob
Other errors are supposed to be catched or avoided by the lib, so if you were to run into an unlisted error, please file an issue.