@awsum-panda/fetchwrapper
v1.0.3
Published
A simple wrapper for fetch with custom error messages
Maintainers
Readme
fetchWrapper
A simple wrapper for fetch with custom error messages
Doc
/**
* @constructor
* @param {string} url - Is required, must be a non-empty string.
* @param {object} options - Defaults to simple GET with json, otherwise takes fetch options object.
* @param {string} custom_err_msg - Optional, defaults to null.
*/Usage
const response = fetchWrapper(url);
response.then((data) => console.log(data));const options = {
method: "GET",
credentials: "include"
headers: {
"Content-Type": "application/json;odata=nometadata",
Accept: "application/json;odata=nometadata",
}
}
const response = fetchWrapper(url,options);
response.then((data) => console.log(data));const customMsg = "Fetch to API failed"
const response = fetchWrapper(url,null,customMsg);
response.then((data) => console.log(data));