Catches a bad request (http code 400) and performs a callback.
Syntactic sugar for error(400, cb)
.
Catches an http response with a specific error code or name and performs a callback.
The original request is passed along the error and can be used in order to perform an additional request.
wretch("/resource")
.get()
.unauthorized(async (error, req) => {
// Renew credentials
const token = await wretch("/renewtoken").get().text();
storeToken(token);
// Replay the original request with new credentials
return req.auth(token).get().unauthorized((err) => {
throw err;
}).json();
})
.json()
// The promise chain is preserved as expected
// ".then" will be performed on the result of the original request
// or the replayed one (if a 401 error was thrown)
.then(callback);
Catches a forbidden request (http code 403) and performs a callback.
Syntactic sugar for error(403, cb)
.
Catches an internal server error (http code 500) and performs a callback.
Syntactic sugar for error(500, cb)
.
Catches a "not found" request (http code 404) and performs a callback.
Syntactic sugar for error(404, cb)
.
Catches a timeout (http code 408) and performs a callback.
Syntactic sugar for error(408, cb)
.
Catches an unauthorized request (http code 401) and performs a callback.
Syntactic sugar for error(401, cb)
.
Read the payload and deserialize it as an ArrayBuffer object.
wretch("...").get().arrayBuffer(arrayBuffer => …)
Optional
cb: ((type: ArrayBuffer) => Result | Promise<Result>)Read the payload and deserialize it as a Blob.
wretch("...").get().blob(blob => …)
Optional
cb: ((type: Blob) => Result | Promise<Result>)Read the payload and deserialize it as a FormData object.
wretch("...").get().formData(formData => …)
Optional
cb: ((type: FormData) => Result | Promise<Result>)Read the payload and deserialize it as JSON.
wretch("...").get().json((json) => console.log(Object.keys(json)));
Optional
cb: ((type: any) => Result | Promise<Result>)The handler for the raw fetch Response. Check the MDN documentation for more details on the Response class.
wretch("...").get().res((response) => console.log(response.url));
Optional
cb: ((type: WretchResponse) => Result | Promise<Result>)Retrieves the payload as a string.
wretch("...").get().text((txt) => console.log(txt));
Optional
cb: ((type: string) => Result | Promise<Result>)Generated using TypeDoc
The resolver interface to chaining catchers and extra methods after the request has been sent. Ultimately returns a Promise.