@@ -222,21 +222,21 @@ export const MsalProvider = ({
222
222
const is401 = error => / 4 0 1 / . test ( error . message )
223
223
const isValid = ( token , expires ) => token && expires > new Date ( ) . getTime ( )
224
224
225
- const retry = async func => {
225
+ const retry = async ( func , returnFullResponse ) => {
226
226
if ( isValid ( idToken , expires ) ) {
227
227
axios . defaults . headers . common . Authorization = `Bearer ${ idToken } `
228
228
try {
229
- const { data } = await func ( )
230
- return data
229
+ const res = await func ( )
230
+ return ! returnFullResponse ? res . data : res
231
231
} catch ( error ) {
232
232
if ( is401 ( error ) ) {
233
233
const accounts = publicClient . getAllAccounts ( )
234
234
if ( accounts && accounts . length > 0 ) await updateToken ( accounts [ 0 ] )
235
235
236
236
axios . defaults . headers . common . Authorization = `Bearer ${ idToken } `
237
237
try {
238
- const { data } = await func ( )
239
- return data
238
+ const res = await func ( )
239
+ return ! returnFullResponse ? res . data : res
240
240
} catch ( error ) {
241
241
console . error ( error )
242
242
return false
@@ -255,10 +255,10 @@ export const MsalProvider = ({
255
255
}
256
256
}
257
257
258
- const apiGet = url = > retry ( ( ) => axios . get ( url ) )
259
- const apiPost = ( url , payload ) => retry ( ( ) => axios . post ( url , payload ) )
260
- const apiPut = ( url , payload ) => retry ( ( ) => axios . put ( url , payload ) )
261
- const apiDelete = url = > retry ( ( ) => axios . delete ( url ) )
258
+ const apiGet = ( url , returnFullResponse = false ) = > retry ( ( ) => axios . get ( url ) , returnFullResponse )
259
+ const apiPost = ( url , payload , returnFullResponse = false ) => retry ( ( ) => axios . post ( url , payload ) , returnFullResponse )
260
+ const apiPut = ( url , payload , returnFullResponse = false ) => retry ( ( ) => axios . put ( url , payload ) , returnFullResponse )
261
+ const apiDelete = ( url , returnFullResponse = false ) = > retry ( ( ) => axios . delete ( url ) , returnFullResponse )
262
262
263
263
return (
264
264
< MsalContext . Provider
0 commit comments