-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to fail a request? #31
Comments
Your current code does not return the promise. and you are using an async function. Your code should look something like this: registerFetchIntercept({
request: async (url: string, options: any): Promise<[string, any]> => {
//Check whether the url matches the regexp
//check whether react native thinks we're offline
const connectionInfo = await NetInfo.getConnectionInfo();
if (connectionInfo.type === "NONE" || connectionInfo.type === "UNKNOWN") {
throw new Error("Reachability Error - Device offline");
}
return [url, options];
},
requestError: (error: any): Promise<void> => {
}
}) Does this what you want? |
No, I need a way to make the code enter the 'requestError; block from within the 'request' block. So far just returning an error, or rejecting the promise doesn't cause that to happen |
Try to register two times. Each registration stands for a registerFetchIntercept({
requestError: (error: any): Promise<void> => {
}
});
registerFetchIntercept({
request: async (url: string, options: any): Promise<[string, any]> => {
//Check whether the url matches the regexp
//check whether react native thinks we're offline
const connectionInfo = await NetInfo.getConnectionInfo();
if (connectionInfo.type === "NONE" || connectionInfo.type === "UNKNOWN") {
throw new Error("Reachability Error - Device offline");
}
return [url, options];
}
}); Maybe this helps. |
Hi, I am using typescript with React Native and node. I need to add an interceptor to check for reachability by verifying whether the device has a network connection. How do I cause a request to fail from within the 'request' block. I have tried throwing an error but I get an 'unhanded promise rejection' error instead.
Here is my code:
i'd love some advice on how to proceed with this?
thanks!
The text was updated successfully, but these errors were encountered: