throw specific HTTPStatusException on http request errors#5551
throw specific HTTPStatusException on http request errors#5551dlang-bot merged 1 commit intodlang:masterfrom
Conversation
|
Thanks for your pull request, @MartinNowak! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
- also see dlang/phobos#5551 for HTTPStatusException
| 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))); |
There was a problem hiding this comment.
This message seems to be rather generic - what was the motivation for not generating this message in HTTPStatusException (or providing a second overload)?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Yes that was my point - if no specific message is passed, this could be the baseline.
There was a problem hiding this comment.
So... not sure what the proposal is here.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Make that const or immutable?
7d227d0 to
926b162
Compare
- also see dlang/phobos#5551 for HTTPStatusException
- also see dlang/phobos#5551 for HTTPStatusException
|
@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( |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
conventionally the call to super goes first in the ctor
| super(msg, file, line, next); | ||
| } | ||
|
|
||
| immutable int status; /// The HTTP status code |
- also see dlang/phobos#5551 for HTTPStatusException
- To make them distinguishable from (e.g. connection) errors and allow appropriate handling in client code.
926b162 to
97e9db7
Compare
|
Done |
| +/ | ||
| class HTTPStatusException : CurlException | ||
| { | ||
| /++ |
| 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. |
There was a problem hiding this comment.
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 :().
|
Can we merge this now? Workaround for the broken coverage is done here #5579. |
- and throw any other errors - also see dlang/phobos#5551 for HTTPStatusException
- and throw any other errors - also see dlang/phobos#5551 for HTTPStatusException
appropriate handling in client code.