@gam-test/fetch-wrapper
Version:
A simple fetch wrapper for better error handling and less response context
25 lines • 802 B
JavaScript
import { HttpClient } from "../HttpClient.js";
import { statusCodeExceptionsMap } from "../exceptions/statusCodeExceptionsMap.js";
class PatchHttpClient extends HttpClient {
async connect({ data, ...config }) {
const response = await fetch(`${this.url}`, {
...config,
method: "PATCH",
body: JSON.stringify(data)
});
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: data,
responseBody
});
}
return response;
}
}
export {
PatchHttpClient
};
//# sourceMappingURL=PatchHttpClient.js.map