123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- 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();
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- const token = await storage.load({
- key: 'token'
- });
- if (method === 'POST' || method === 'PATCH' || method === 'DELETE' || method === 'PUT') {
- options.headers = {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json',
- "uid": 'c2e13090a563447c8744a8c03171d1db',
- 'token': token? token : null
- };
- options.body = JSON.stringify(options.body)
- }else {
- options.headers = {
- 'token': await storage.load({
- key: 'token'
- })
- };
- }
- }
- console.log('options',options)
- return fetch(url, options)
- .then(checkStatus)
- .then(parseJSON)
- .then(checkAPIDatas)
- .catch(checkAPIError);
- }
- export default request
|