123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- 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) => {
- const file_uid = await getuid();
- if (options) {
- const method = options.method.toUpperCase();
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- options.headers = {
- Accept: 'application/json',
- 'Content-Type': 'application/json',
- uid: file_uid
-
- };
- 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);
- };
- async function getuid() {
- const uid = await storage
- .load({
- key: 'userInfo'
- })
- .catch((error) => {
- return '';
- });
- if (uid === '') {
- return '';
- }
- return JSON.parse(uid).uid;
- }
- export default request;
|