Skip to content

throw specific HTTPStatusException on http request errors#5551

Merged
dlang-bot merged 1 commit intodlang:masterfrom
MartinNowak:http_status_exception
Jul 8, 2017
Merged

throw specific HTTPStatusException on http request errors#5551
dlang-bot merged 1 commit intodlang:masterfrom
MartinNowak:http_status_exception

Conversation

@MartinNowak
Copy link
Member

  • To make them distinguishable from (e.g. connection) errors and allow
    appropriate handling in client code.

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @MartinNowak!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

MartinNowak added a commit to MartinNowak/dub that referenced this pull request Jul 5, 2017
format("HTTP request returned status code %d (%s)",
statusLine.code, statusLine.reason));
enforce(statusLine.code / 100 == 2, new HTTPStatusException(statusLine.code,
format("HTTP request returned status code %d (%s)", statusLine.code, statusLine.reason)));
Copy link
Contributor

Choose a reason for hiding this comment

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

This message seems to be rather generic - what was the motivation for not generating this message in HTTPStatusException (or providing a second overload)?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's the baseline of a useful error message but doesn't contain enough information on it's own (e.g. the url or the status reason), those are only available by the calling code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes that was my point - if no specific message is passed, this could be the baseline.

Copy link
Member

Choose a reason for hiding this comment

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

So... not sure what the proposal is here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sth. like below could be handy, but I don't feel strongly about this (I am not using std.net.curl anyways):

@safe pure nothrow
this(int status,
  string file = __FILE__,
  size_t line = __LINE__,
  Throwable next = null)
{
  const msg = format("HTTP request returned status code %d", status);
  super(msg, file, line, next);
  this.status = status;
}

@safe pure nothrow
this(int status,
  string msg,
  string file = __FILE__,
  size_t line = __LINE__,
  Throwable next = null)
{
  const _msg = format("HTTP request returned status code %d (%s)", status, msg);
  super(_msg, file, line, next);
  this.status = status;
}

std/net/curl.d Outdated
super(msg, file, line, next);
}

int status; /// The HTTP status code
Copy link
Member

Choose a reason for hiding this comment

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

Make that const or immutable?

@MartinNowak MartinNowak force-pushed the http_status_exception branch from 7d227d0 to 926b162 Compare July 7, 2017 22:26
MartinNowak added a commit to MartinNowak/dub that referenced this pull request Jul 7, 2017
MartinNowak added a commit to MartinNowak/dub that referenced this pull request Jul 7, 2017
@wilzbach
Copy link
Contributor

wilzbach commented Jul 8, 2017

@ZombineDev there is still the rule that new symbols should be approved by @andralex (we should really document these and make a handy guide out of them)

std/net/curl.d Outdated
next = The previous exception in the chain of exceptions, if any.
+/
@safe pure nothrow
this(
Copy link
Member

Choose a reason for hiding this comment

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

this line should be flush with the attributes, i.e.

@safe pure nothrow
this(

Throwable next = null)
{
this.status = status;
super(msg, file, line, next);
Copy link
Member

Choose a reason for hiding this comment

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

conventionally the call to super goes first in the ctor

super(msg, file, line, next);
}

immutable int status; /// The HTTP status code
Copy link
Member

Choose a reason for hiding this comment

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

immutable -> nice!

@andralex andralex removed the @andralex label Jul 8, 2017
MartinNowak added a commit to MartinNowak/dub that referenced this pull request Jul 8, 2017
- To make them distinguishable from (e.g. connection) errors and allow
  appropriate handling in client code.
@MartinNowak MartinNowak force-pushed the http_status_exception branch from 926b162 to 97e9db7 Compare July 8, 2017 12:02
@MartinNowak
Copy link
Member Author

Done

+/
class HTTPStatusException : CurlException
{
/++
Copy link
Member

Choose a reason for hiding this comment

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

eh, bug in -cov

status = The HTTP status code.
msg = The message for the exception.
file = The file where the exception occurred.
line = The line number where the exception occurred.
Copy link
Member

Choose a reason for hiding this comment

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

eh, another bug in -cov

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks weird https://codecov.io/gh/dlang/phobos/compare/ecef6f0e3b3da14d483b3dd6e05d8780d16fd719...97e9db7f02ea072acb1a3f1bd11e3a1f3fca193a/changes, but if I run the single test locally dmd reports correct coverage.
It's also weird what we're doing the circleci script, looks like tests are supposed to run twice but fail to do so.
https://circleci.com/gh/dlang/phobos/3504 (no log line links in circleci :().

@MartinNowak
Copy link
Member Author

Can we merge this now? Workaround for the broken coverage is done here #5579.

@dlang-bot dlang-bot merged commit 4cfe0f3 into dlang:master Jul 8, 2017
MartinNowak added a commit to MartinNowak/dub that referenced this pull request Jul 9, 2017
- and throw any other errors
- also see dlang/phobos#5551 for HTTPStatusException
@MartinNowak MartinNowak deleted the http_status_exception branch July 9, 2017 13:08
MartinNowak added a commit to MartinNowak/dub that referenced this pull request Jul 10, 2017
- and throw any other errors
- also see dlang/phobos#5551 for HTTPStatusException
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants