cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: error handling in non-html transfer

From: Ralph Mitchell <ralphmitchell_at_gmail.com>
Date: Fri, 22 Mar 2013 12:42:16 -0400

On Fri, Mar 22, 2013 at 11:26 AM, Adam Kellas <adam.kellas_at_gmail.com> wrote:

> I'm using http as a general-purpose transport protocol to send files to a
> server where they're processed and returned to a command line program. This
> is basically working, it's just error handling I'm struggling with.
>
> A browser handles errors by rendering an error message in html and not
> exiting, but my client needs to behave just like a normal command-line
> program. The fact that it hands the job off to a server should be an
> implementation detail, but printing error messages to stderr and exiting
> with a meaningful status are a problem.
>
> I'm currently using this command on the client side:
>
> % curl -o bar -F inputfile=@foo
>
> When things go well the right data ends up in "bar", but if it fails curl
> still exits with 0 leaving something like "500 Internal Server Error" in
> it. Is there a way the server can tell curl, or any http client, to print
> the body to stderr and exit nonzero? To be clear, I'm hoping to be able to
> use the curl program as my client side but if I need to write a custom
> client that could be done too. I've thought about adding a custom header
> like X-ErrorMessage but don't know if curl could process that.
>
I think you're getting the return code 0 because as far as curl is
concerned, the interaction with the web server is successful - i.e. it
responded, allowed the connection, accepted the upload, etc.

If you can have the server send a customized header back, you could use the
--dump-header option to save all the headers in a file for further
examination.

Ralph Mitchell

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-03-22