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

Error Object, remove unnecessary new keywords, format code #10

Merged
merged 1 commit into from Oct 19, 2019
Merged

Error Object, remove unnecessary new keywords, format code #10

merged 1 commit into from Oct 19, 2019

Conversation

ghost
Copy link

@ghost ghost commented Sep 25, 2019

This commit adresses Issue #9 .
I've changed the json dummy provider to https://reqres.in/
Removed unnecessary new keyword: Don't use new
Formatting code with dartfmt

Added:

  • shouldThrow: bool → Default: true (whether the request should throw an error with the Request object, the default is true to keep minimum compatibility)
  • dataOnly: bool → Default: true (whether the request should return only the response and not the Request object, the default is true to keep minimum compatibility)

@ghost
Copy link
Author

ghost commented Sep 25, 2019

I think that the only breaking change would be the throw when the request returns with Client or Server error, where people could be querying for the error code in the Exception string (in previous version).

onError.publish(errorEvent);
throw Exception("Invalid HTTP status code $statusCode for url $url");
throw Response(responseContent, statusCode, !hasClientOrServerError);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to throw a custom exception with all data in his instance

throw HTTPException(message, statusCode, responseContent)

try {
await Requests.get('$PLACEHOLDER_PROVIDER/api/unknown/23',
shouldThrow: true);
} catch (resp) {
Copy link
Owner

@jossef jossef Oct 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here I would catch the specific custom exception and read the data stored on his instance

Suggested change
} catch (resp) {
} on HTTPException catch (e) {

@jossef jossef merged commit 2a326bc into jossef:master Oct 19, 2019
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

Successfully merging this pull request may close these issues.

1 participant