react-native-simple-networking
Advanced tools
Comparing version
@@ -105,3 +105,11 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const report = {}; | ||
if (!axios_1.default.isAxiosError(error)) { | ||
console.log("Non axios error: "); | ||
console.log(JSON.stringify(error, null, 4)); | ||
return; | ||
} | ||
if (!error.config) { | ||
console.log("Error had no config..."); | ||
return; | ||
} | ||
console.log("Unhandled Axios Error - " + `${error.config.method} ${error.config.url}`); | ||
@@ -113,20 +121,8 @@ console.log("Headers: "); | ||
console.log(error.config.data); | ||
report.data = JSON.parse(error.config.data); | ||
} | ||
; | ||
// For easier copy / pasting | ||
report.headers = error.config.headers; | ||
report.method = error.config.method; | ||
report.url = error.config.url; | ||
if (error.config.baseURL) | ||
report.baseUrl = error.config.baseURL; | ||
console.log("Report: "); | ||
console.log(JSON.stringify(report, null, 4)); | ||
}); | ||
} | ||
axiosClient.interceptors.response.use(undefined, (error) => __awaiter(this, void 0, void 0, function* () { | ||
if (error.response) { | ||
console.log("RESPONSE ERROR: "); | ||
console.log(JSON.stringify(error, null, 4)); | ||
} | ||
if ('response' in error && error.response && (attemptRefreshOnStatusCodes.includes(error.response.status))) { | ||
@@ -133,0 +129,0 @@ yield onUnauthorizedRequest(error.config); |
{ | ||
"name": "react-native-simple-networking", | ||
"version": "1.0.12", | ||
"version": "1.0.13", | ||
"description": "This is a package that implements authentication state using zustand tied to axios interceptors in order to automatically add an 'authorization' header to all requests any time a request is sent with the created axios client. It also provides some basic request logging. The package will attempt to refresh any time an access token is expired, stalling all requests any time a token refresh is going on. ", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -125,3 +125,11 @@ import axios, { AxiosError, AxiosRequestConfig } from "axios"; | ||
async function logAxiosError(error: AxiosError) { | ||
const report: any = {}; | ||
if(!axios.isAxiosError(error)) { | ||
console.log("Non axios error: ") | ||
console.log(JSON.stringify(error, null, 4)); | ||
return; | ||
} | ||
if(!error.config) { | ||
console.log("Error had no config...") | ||
return | ||
} | ||
console.log("Unhandled Axios Error - " + `${error.config.method} ${error.config.url}`) | ||
@@ -134,21 +142,10 @@ console.log("Headers: ") | ||
console.log(error.config.data); | ||
report.data = JSON.parse(error.config.data); | ||
}; | ||
// For easier copy / pasting | ||
report.headers = error.config.headers; | ||
report.method = error.config.method; | ||
report.url = error.config.url; | ||
if(error.config.baseURL) | ||
report.baseUrl = error.config.baseURL; | ||
console.log("Report: ") | ||
console.log(JSON.stringify(report, null, 4)) | ||
} | ||
axiosClient.interceptors.response.use(undefined, async (error: AxiosError) => { | ||
if(error.response) { | ||
console.log("RESPONSE ERROR: ") | ||
console.log(JSON.stringify(error, null, 4)) | ||
} | ||
if ('response' in error && error.response && (attemptRefreshOnStatusCodes.includes(error.response.status))) { | ||
@@ -155,0 +152,0 @@ await onUnauthorizedRequest(error.config); |
21623
-2.19%514
-1.53%