1.0.3 • Published 1 year ago

@awsum-panda/fetchwrapper v1.0.3

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 year ago

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));

GitHub Tag

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago