fbjs
fbjs copied to clipboard
Handle network errors / make it possible to alter request on error
I use it like this:
var token = localStorage.getItem('jwtToken');
const g = require('../../misc/settings').graphql;
Relay.injectNetworkLayer(
new RelayNetworkLayer('http://'+g.host+':'+g.port+'/graphql', {
headers: (token ? {
Authorization: 'Bearer ' + token
} : {}),
onError: (error, init) => {
console.log(error);
if(error.status == 400 || error.status == 500) {
localStorage.removeItem('jwtToken');
delete init.headers['Authorization'];
console.log('removed token');
return true; // directly retry request
}
return false;
}
})
);
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks!
If you are contributing on behalf of someone else (eg your employer): the individual CLA is not sufficient - use https://developers.facebook.com/opensource/cla?type=company instead. Contact [email protected] if you have any questions.