phobos icon indicating copy to clipboard operation
phobos copied to clipboard

Improve error reporting for std.curl.net

Open dlangBugzillaToGithub opened this issue 4 years ago • 0 comments

lance (@bachmeil) reported this on 2021-07-25T15:37:27Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=22142

Description

std.net.curl doesn't provide information when something fails. Consider the following (not terribly obvious) typo:

client.addRequestHeader("Content-Type", "Application/json");

followed by a call to post:

post("https://api.todoist.com/rest/v1/tasks", cmd, client);

You get only a generic error message:

HTTP request returned status code 400 ()

Compare this with the error message if you do the same thing with command line curl. The message is:

Empty content

That immediately points you in the right direction. What is the typo? The line at the beginning should be

client.addRequestHeader("Content-Type", "application/json");

"Status code 400" does not help. "Empty content" does.

dlangBugzillaToGithub avatar Jul 25 '21 15:07 dlangBugzillaToGithub