Skip to content
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

Access to native error / request error type to differentiate network errors #61

Open
dpattou opened this issue Nov 9, 2021 · 2 comments

Comments

@dpattou
Copy link

dpattou commented Nov 9, 2021

Hello, I might have missed something, but it doesn't seem possible to retrieve the original / native errors thrown on iOS and Android by their respective networking libraries in order to determine whether the error is a network error, a timeout error or another kind of error.

Is there a way to get this information ? Or an easy way around the fact that errors returned by the @klippa/nativescript-http plugin are strings ?

For my use case, I managed to naively parse the returned strings and deduce the error but it turns out the iOS implementation returns an Error(error.localizedDescription) so parsing won't work in that case :)

Any tip would be much appreciated.

Thanks, great plugin otherwise !

@jerbob92
Copy link
Contributor

jerbob92 commented Nov 9, 2021

Hey!

At this moment, I don't think it's possible to get the original native error. I'm also not sure whether NativeScript has something to provide in that. It's probably better to transform these errors in the plugin to standardized TypeScript errors.
I would accept Pull Requests for that.

@dpattou
Copy link
Author

dpattou commented Nov 12, 2021

Thanks for the answer.

We cannot get the actual native error indeed, I meant the 'wrapped' Javascript version.

On iOS the error returned by session.dataTaskWithRequestCompletionHandler(urlRequest, function (data, response, error) {...} seems to be a 'wrapped' Javascript NSError. On Android though, I'm not sure what errors are mapped to (probably some subclass of a java Exception ?).

I guess it would be somewhat complicated to map iOS NSErrors and Android Exceptions to various error types (no network, timeout etc...) but it might be nice to have a way to retrieve the 'original' (but not native :) ) error.

I'm not super familiar with TypeScript errors, but it looks like one would have to create a subclass for that ? (And add an nativeError / underlyingError property to the Error class).

I don't have a lot of time to delve more into this right now but may try to make a pull request later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants