Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
db.open().catch(async err => {
console.error(err)
// NOTE - invalid state error suggests dexie not supported, so
// try reloading with cachedb disabled (see db index for implementation)
if (err.name === Dexie.errnames.InvalidState) {
if (err.inner.name === Dexie.errnames.InvalidState) {
location.replace(location.href + '?no-cache')
}
}
// NOTE - upgrade error can be avoided by defining legacy db caches
// with corresponding upgrade functions (see below method TODO)
if (err.name === Dexie.errnames.Upgrade) {
await Dexie.delete(CACHE_DB_NAME).catch(() => location.reload())
return location.reload()
}
})
}
db.open().catch(async err => {
console.error(err)
// NOTE - invalid state error suggests dexie not supported, so
// try reloading with cachedb disabled (see db index for implementation)
if (err.name === Dexie.errnames.InvalidState) {
if (err.inner.name === Dexie.errnames.InvalidState) {
location.replace(location.href + '?no-cache')
}
}
// NOTE - upgrade error can be avoided by defining legacy db caches
// with corresponding upgrade functions (see below method TODO)
if (err.name === Dexie.errnames.Upgrade) {
await Dexie.delete(CACHE_DB_NAME).catch(() => location.reload())
return location.reload()
}
})
}
promise.catch(function(error) {
selfoss.ui.showError(selfoss.ui._('error_offline_storage', [error.message]));
selfoss.db.storage = null;
selfoss.db.reloadList();
// If this is a QuotaExceededError, garbage collect more
// entries and hope it helps.
if (error.name === Dexie.errnames.QuotaExceeded) {
selfoss.dbOffline.GCEntries(true);
}
throw error;
});
export const initErrHandler = (defReturnVal: T = null) => (
err: Dexie.DexieError,
) => {
if (
err.message === 'Data fetch failed' ||
(err.name === Dexie.errnames.OpenFailed &&
err.message.includes('createObjectStore'))
) {
return defReturnVal
}
throw err
}
private mapDatabaseError(
error: Dexie.DexieError,
tableName: string,
primaryKey: PrimaryKey,
): Error {
const isAlreadyExisting = error instanceof Dexie.ConstraintError;
/** @see https://github.com/dfahlander/Dexie.js/issues/776 */
const hasNotEnoughDiskSpace =
error.name === Dexie.errnames.QuotaExceeded || error.inner?.name === Dexie.errnames.QuotaExceeded;
if (isAlreadyExisting) {
const message = `Record "${primaryKey}" already exists in "${tableName}". You need to delete the record first if you want to overwrite it.`;
return new StoreEngineError.RecordAlreadyExistsError(message);
} else if (hasNotEnoughDiskSpace) {
const message = `Cannot save "${primaryKey}" in "${tableName}" because there is low disk space.`;
return new StoreEngineError.LowDiskSpaceError(message);
} else {
return error;
}
}
private mapDatabaseError(error: Dexie.DexieError, tableName: string, primaryKey: string): Error {
const isAlreadyExisting = error instanceof Dexie.ConstraintError;
/** @see https://github.com/dfahlander/Dexie.js/issues/776 */
const hasNotEnoughDiskSpace =
error.name === Dexie.errnames.QuotaExceeded || (error.inner && error.inner.name === Dexie.errnames.QuotaExceeded);
if (isAlreadyExisting) {
const message = `Record "${primaryKey}" already exists in "${tableName}". You need to delete the record first if you want to overwrite it.`;
return new StoreEngineError.RecordAlreadyExistsError(message);
} else if (hasNotEnoughDiskSpace) {
const message = `Cannot save "${primaryKey}" in "${tableName}" because there is low disk space.`;
return new StoreEngineError.LowDiskSpaceError(message);
} else {
return error;
}
}
}