Add reject body interface.
This commit is contained in:
parent
ff17d3b02f
commit
27914d4a7d
@ -87,3 +87,10 @@ export class GlobalErrorHandler extends ErrorHandler {
|
|||||||
return isWarning;
|
return isWarning;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function rejectBody(error): { status: any; statusText: any } {
|
||||||
|
return {
|
||||||
|
status: error.status,
|
||||||
|
statusText: error.statusText,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { rejectBody } from '@app/_helpers/global-error-handler';
|
||||||
|
|
||||||
function HttpGetter(): void {}
|
function HttpGetter(): void {}
|
||||||
|
|
||||||
HttpGetter.prototype.get = (filename) =>
|
HttpGetter.prototype.get = (filename) =>
|
||||||
@ -6,7 +8,7 @@ HttpGetter.prototype.get = (filename) =>
|
|||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
resolve(response.json());
|
resolve(response.json());
|
||||||
} else {
|
} else {
|
||||||
reject(`failed with status ${response.status} : ${response.statusText}`);
|
reject(rejectBody(response));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
|
@ -6,7 +6,7 @@ import { LoggingService } from '@app/_services/logging.service';
|
|||||||
import { MutableKeyStore, MutablePgpKeyStore } from '@app/_pgp';
|
import { MutableKeyStore, MutablePgpKeyStore } from '@app/_pgp';
|
||||||
import { ErrorDialogService } from '@app/_services/error-dialog.service';
|
import { ErrorDialogService } from '@app/_services/error-dialog.service';
|
||||||
import { HttpClient } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { HttpError } from '@app/_helpers/global-error-handler';
|
import { HttpError, rejectBody } from '@app/_helpers/global-error-handler';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
@ -50,10 +50,7 @@ export class AuthService {
|
|||||||
};
|
};
|
||||||
fetch(environment.cicMetaUrl, options).then((response) => {
|
fetch(environment.cicMetaUrl, options).then((response) => {
|
||||||
if (response.status === 401) {
|
if (response.status === 401) {
|
||||||
return reject({
|
return reject(rejectBody(response));
|
||||||
status: response.status,
|
|
||||||
statusText: response.statusText,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return resolve(true);
|
return resolve(true);
|
||||||
});
|
});
|
||||||
@ -73,10 +70,7 @@ export class AuthService {
|
|||||||
};
|
};
|
||||||
fetch(environment.cicMetaUrl, options).then((response) => {
|
fetch(environment.cicMetaUrl, options).then((response) => {
|
||||||
if (response.status === 401) {
|
if (response.status === 401) {
|
||||||
return reject({
|
return reject(rejectBody(response));
|
||||||
status: response.status,
|
|
||||||
statusText: response.statusText,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
this.sessionToken = response.headers.get('Token');
|
this.sessionToken = response.headers.get('Token');
|
||||||
sessionStorage.setItem(btoa('CICADA_SESSION_TOKEN'), this.sessionToken);
|
sessionStorage.setItem(btoa('CICADA_SESSION_TOKEN'), this.sessionToken);
|
||||||
@ -94,10 +88,7 @@ export class AuthService {
|
|||||||
return resolve(hobaParseChallengeHeader(authHeader));
|
return resolve(hobaParseChallengeHeader(authHeader));
|
||||||
}
|
}
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
return reject({
|
return reject(rejectBody(response));
|
||||||
status: response.status,
|
|
||||||
statusText: response.statusText,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -206,12 +197,14 @@ export class AuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getPublicKeys(): Promise<any> {
|
async getPublicKeys(): Promise<any> {
|
||||||
return await fetch(environment.publicKeysUrl).then((res) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
fetch(environment.publicKeysUrl).then((res) => {
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
// TODO does angular recommend an error interface?
|
// TODO does angular recommend an error interface?
|
||||||
throw Error(`${res.statusText} - ${res.status}`);
|
return reject(rejectBody(res));
|
||||||
}
|
}
|
||||||
return res.text();
|
return resolve(res.text());
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user