Skip to content

Non-localized error description in ClientException #1442

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

Closed
jv-soares opened this issue Jan 7, 2025 · 2 comments · Fixed by #1763
Closed

Non-localized error description in ClientException #1442

jv-soares opened this issue Jan 7, 2025 · 2 comments · Fixed by #1763
Assignees
Labels
package:cupertino_http Issues related to package:cupertino_http type-enhancement A request for a change that isn't a bug

Comments

@jv-soares
Copy link

Hey guys this is rather a question than a feature request.

The problem im facing is that some ClientException errors sent to my crash reporting tool are unreadable and hard to group because they contain localized messages.

For instance, I see ClientException: Неможливо встановити з’єднання для передавання даних, бо триває виклик as an error message and i have no idea what it means.

By taking a quick look at cupertino_client.dart i could find how a ClientException is constructed using NSError.localizedDescription

static void _onComplete(URLSession session, URLSessionTask task, NSError? error) {
    final taskTracker = _tracker(task);
    if (error != null) {
      final exception = ClientException(error.localizedDescription.toString(), taskTracker.request.url);
...

so my question is: is it possible to use a non-localized description instead?

@jv-soares jv-soares added package:cupertino_http Issues related to package:cupertino_http type-enhancement A request for a change that isn't a bug labels Jan 7, 2025
@brianquinlan
Copy link
Collaborator

@jv-soares I don't think that there is a non-localized user-friendly description. Would it be sufficient to provide a ClientException subclass that allows you to access the underlying NSError?

You'd probably want to extract error.code (e.g. -1003 for domain not found) and error.domain (e.g. 'NSURLErrorDomain').

The code would look something like:

try {
  client...
} on NSErrorClientException catch (e) {
  print(e.error.code);
} on ClientException catch(e) {
  // Handle ClientException as normal
} 

@brianquinlan
Copy link
Collaborator

I have a PR out that captures this idea: https://github.com/dart-lang/http/pull/1763/files

Notice how the stringification of the exception includes the error code and domain, which should be the same in across languages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:cupertino_http Issues related to package:cupertino_http type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants