Commit 4f5668f5 authored by Alexander Philipp Nowosad's avatar Alexander Philipp Nowosad
Browse files

Fix name of checkSessionExpired

parent c43106a9
......@@ -74,7 +74,7 @@ export class PouchdbService {
* Get info about the database
*/
getDatabaseInfo(): Promise<PouchDB.Core.DatabaseInfo> {
return this.db.info().catch((error) => this.checkSessionExpired(error));
return this.db.info().catch((error) => this.handleError(error));
}
find<T extends PouchdbModel>(
......@@ -89,7 +89,7 @@ export class PouchdbService {
$and: [request.selector, { type }],
},
})
.catch((error) => this.checkSessionExpired(error)) as Promise<
.catch((error) => this.handleError(error)) as Promise<
PouchDB.Find.FindResponse<T>
>;
} else {
......@@ -100,32 +100,30 @@ export class PouchdbService {
type,
},
})
.catch((error) => this.checkSessionExpired(error)) as Promise<
.catch((error) => this.handleError(error)) as Promise<
PouchDB.Find.FindResponse<T>
>;
}
}
get<T extends PouchdbModel>(id: string) {
return this.db.get<T>(id).catch((error) => this.checkSessionExpired(error));
return this.db.get<T>(id).catch((error) => this.handleError(error));
}
post<T extends PouchdbModel>(model: T) {
return this.db
.post(model.toPouchDb())
.catch((error) => this.checkSessionExpired(error));
.catch((error) => this.handleError(error));
}
put<T extends PouchdbModel>(model: T) {
return this.db
.put(model.toPouchDb())
.catch((error) => this.checkSessionExpired(error));
.catch((error) => this.handleError(error));
}
remove<T extends PouchdbModel>(model: T) {
return this.db
.remove(model)
.catch((error) => this.checkSessionExpired(error));
return this.db.remove(model).catch((error) => this.handleError(error));
}
/**
......@@ -145,15 +143,15 @@ export class PouchdbService {
.on('change', (change) => this.zone.run(() => subject.next(change)))
.on('error', (error) => this.zone.run(() => subject.error(error)));
return subject.pipe(
catchError((error) => from(this.checkSessionExpired(error))),
catchError((error) => from(this.handleError(error))),
finalize(() => changes.cancel())
);
}
/**
* Called when the session cookie is expired
* Called on error
*/
private async checkSessionExpired(error): Promise<any> {
private async handleError(error): Promise<any> {
if (
error.status === 401 &&
error.error === 'unauthorized' &&
......@@ -177,7 +175,7 @@ export class PouchdbService {
async addDefaultData() {
return this.db
.bulkDocs(examples as any[])
.catch((error) => this.checkSessionExpired(error));
.catch((error) => this.handleError(error));
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment