EPrints Technical Mailing List Archive
See the EPrints wiki for instructions on how to join this mailing list and related information.
Message: #07337
< Previous (by date) | Next (by date) > | < Previous (in thread) | Next (in thread) > | Messages - Most Recent First | Threads - Most Recent First
[EP-tech] Sending out Error Statuses with Error codes
- To: "eprints-tech@ecs.soton.ac.uk" <eprints-tech@ecs.soton.ac.uk>
- Subject: [EP-tech] Sending out Error Statuses with Error codes
- From: Adam Field <adam@adamfield.net>
- Date: Tue, 26 Jun 2018 17:00:40 +0100
| Hi                 I’m working on an API that spits out objects in JSON, and I have a function that handles errors.  I can’t seem to get it to behave, and I wonder if anyone can offer me any advice. sub api_error {         my ($repo, $code, $message) = @_;         my $r = $repo->request;         $r->status($code);         EPrints::Apache::AnApache::send_status_line( $r, $code );         $r->content_type('application/json');         my $json = JSON->new;         my $content = $json->encode(         {                 status => $code,                 message => $message         }         );         $r->err_headers_out->{'Content-Length'} = length $content; #       binmode(STDOUT, ":utf8"); #       print $content;         return $code; } Using CURL to look at the headers and body, I get this: HTTP/1.1 400 Bad Request Date: Tue, 26 Jun 2018 15:48:51 GMT Server: Apache/2.4.7 (Ubuntu) Content-Length: 120 Connection: close Content-Type: text/html; charset=iso-8859-1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>400 Bad Request</title> </head><body> <h1>Bad Request</h1> <p>Your browser sent a request that this server could not understand.<br /> </p> <hr> <address>Apache/2.4.7 (Ubuntu) Server at sherpaneo-test.sherpa.ac.uk Port 443</address> </body></html> If I uncomment the two commented lines, I get this: HTTP/1.1 200 OK Date: Tue, 26 Jun 2018 15:48:36 GMT Server: Apache/2.4.7 (Ubuntu) Content-Length: 120 Content-Type: application/json {"message":"unrecognised api key in 'api-key' at /usr/share/eprints3/lib/plugins/SherpaAPI.pm line 470.\n","status":400} Essentially, if I output anything to STDOUT, something (maybe MOD Perl) switches the status to ‘200 OK’.  How can I get the status code from the first version, and the body from the second?  Any ideas? Cheers -- Adam Field | 
- Follow-Ups:
- [EP-tech] Sending out Error Statuses with Error codes
- From: Adam Field <adam@adamfield.net>
 
 
- [EP-tech] Sending out Error Statuses with Error codes
- References:
- [EP-tech] Sending out Error Statuses with Error codes
- From: Adam Field <adam@adamfield.net>
 
 
- [EP-tech] Sending out Error Statuses with Error codes
- Prev by Date: [EP-tech] About Orcid Support Advzanced plugin
- Next by Date: Re: [EP-tech] Sending out Error Statuses with Error codes
- Previous by thread: [EP-tech] EPrints/CRIS
- Next by thread: [EP-tech] DOI handling in orcid_support_advance
- Index(es):
