Skip to content

Commit 85ce782

Browse files
authored
Merge pull request #25 from JamesAPetts/errorInterceptor
Error interceptor
2 parents 0b2b86e + d8b4f76 commit 85ce782

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/api.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ class DICOMwebClient {
7171
this.stowURL = this.baseURL;
7272
}
7373

74+
// Headers to pass to requests.
7475
this.headers = options.headers || {};
76+
77+
// Optional error interceptor callback to handle any failed request.
78+
this.errorInterceptor = options.errorInterceptor || function() {};
7579
}
7680

7781
static _parseQueryParameters(params = {}) {
@@ -86,6 +90,9 @@ class DICOMwebClient {
8690
}
8791

8892
_httpRequest(url, method, headers, options = {}) {
93+
94+
const {errorInterceptor} = this;
95+
8996
return new Promise((resolve, reject) => {
9097
const request = new XMLHttpRequest();
9198
request.open(method, url, true);
@@ -136,6 +143,8 @@ class DICOMwebClient {
136143
console.error(error);
137144
console.error(error.response);
138145

146+
errorInterceptor(error);
147+
139148
reject(error);
140149
}
141150
}

0 commit comments

Comments
 (0)