Skip to content

Commit d9221eb

Browse files
committed
Adds improvements for errorhandling.
1 parent 6eb6993 commit d9221eb

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@apaq/leap-http",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/errors/default-error-handler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ type Error = {
55
}
66

77
export class DefaultErrorHandler implements ErrorHandler {
8-
hasError(response: Response): boolean {
8+
hasError(request: Request, response: Response): boolean {
99
return !response.ok;
1010
}
1111

12-
handleError(response: Response): Promise<void> {
12+
async handleError(response: Response): Promise<void> {
1313
const statusCode = response.status;
1414
if (statusCode == null || statusCode === 0) {
1515
throw new Error('Unknown status code retruend from server');
1616
}
17-
return this.doHandleError(response, statusCode);
17+
return await this.doHandleError(response, statusCode);
1818
}
1919

2020
private async doHandleError(response: Response, statusCode: number): Promise<void> {

src/errors/error-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

22
export interface ErrorHandler {
3-
hasError(response: Response): boolean;
3+
hasError(request: Request, response: Response): boolean;
44
handleError(response: Response): Promise<void>;
55
}

src/http/client/rest-template.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class RestTemplate implements RestOperations {
3636
const request = await this.requestFactory.createRequest(uri, method, output?.body, finalHeaders);
3737
return new Promise<ResponseEntity>((resolve, reject) => {
3838
this.handleFetch(request)
39-
.then(response => this.handleErrors(response))
39+
.then(response => this.handleErrors(request, response))
4040
.then(response => this.handleData(response))
4141
.then(([data, response]) => resolve({headers: response.headers, body: data, status: response.status, statusText: response.statusText}))
4242
.catch(error => reject(error));
@@ -89,8 +89,8 @@ export class RestTemplate implements RestOperations {
8989
}
9090
}
9191

92-
private async handleErrors(response: Response): Promise<Response> {
93-
const hasError = this.errorHandler.hasError(response);
92+
private async handleErrors(request: Request, response: Response): Promise<Response> {
93+
const hasError = this.errorHandler.hasError(request, response);
9494

9595
if (hasError) {
9696
await this.errorHandler.handleError(response);

0 commit comments

Comments
 (0)