Created
April 28, 2018 04:52
-
-
Save wldcordeiro/36fc6c4be13f12b20205f2447b1e1c7f to your computer and use it in GitHub Desktop.
converting to RxJS 6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function retryAuth(req$, params) { | |
return req$.retryWhen(errors => | |
errors.mergeMap(error => { | |
if (error.status === httpStatus.UNAUTHORIZED) { | |
// If rawAjax is successful, it will retry | |
return rawAjax({ | |
...params, | |
url: '/authentication/reup', | |
}).catch(err => { | |
// Reupping was not allowed. Redirect to login | |
if (err.status === httpStatus.UNAUTHORIZED) { | |
redirectToAuth() | |
return Observable.throw(error) | |
} | |
return Observable.throw(error) | |
}) | |
} | |
return Observable.throw(error) | |
}) | |
) | |
} | |
const raw = (...params) => { | |
return retryAuth(ajax(...params), defaultParameters).catch( | |
err => { | |
// Report the error | |
ReportError.next(formatError(err)) | |
// Return the original error, so that it can be handled individually | |
return Observable.throw(err) | |
} | |
) | |
} | |
const withMethod = method => (...params) => { | |
return retryAuth( | |
ajax({ ...params, method }), | |
defaultParameters | |
).catch(err => { | |
// Report the error | |
ReportError.next(formatError(err)) | |
// Return the original error, so that it can be handled individually | |
return Observable.throw(err) | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
incommmming |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment