@gam-test/fetch-wrapper
Version:
A simple fetch wrapper for better error handling and less response context
24 lines • 747 B
JavaScript
import { HttpClient } from "../HttpClient.js";
import { statusCodeExceptionsMap } from "../exceptions/statusCodeExceptionsMap.js";
class GetHttpClient extends HttpClient {
async connect(config) {
const response = await fetch(`${this.url}`, {
...config,
method: "GET"
});
const requestException = statusCodeExceptionsMap.get(response.status);
if (requestException && config?.throwOnConnectionFailure) {
const responseBody = await response.json().catch(() => "Request response with non json body");
throw new requestException({
url: this.url,
payload: null,
responseBody
});
}
return response;
}
}
export {
GetHttpClient
};
//# sourceMappingURL=GetHttpClient.js.map