123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- function checkStatus(response) {
- console.log("res1", response);
- if (response.status >= 200 && response.status < 300) {
- return response;
- }
- const error = new Error(response.statusText);
- error.response = response;
- throw error;
- }
- function parseJSON(response) {
- return response.json();
- }
- function checkAPIDatas(data) {
- console.log("data", data);
- if (!data.success) {
- const code = data;
- }
- return data;
- }
- function checkAPIError(err) {
- console.log("err", err);
-
-
-
-
- return {
- err
- };
- }
- const request = async (url, options) => {
-
-
-
-
-
- if (options) {
- const method = options.method.toUpperCase();
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- options.headers = {
- Accept: "application/json",
- "Content-Type": "application/json",
- uid: "c2e13090a563447c8744a8c03171d1db"
-
- };
- if (
- method === "POST" ||
- method === "PATCH" ||
- method === "DELETE" ||
- method === "PUT"
- ) {
- options.body = JSON.stringify(options.body);
- }
-
-
-
-
-
-
-
- }
- console.log("options", options);
- return fetch(url, options)
- .then(checkStatus)
- .then(parseJSON)
- .then(checkAPIDatas)
- .catch(checkAPIError);
- };
- export default request;
|