You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Tom Hill <so...@zvents.com> on 2007/07/27 00:41:14 UTC

Returning errors from request handler

Hi -

With solr 1.2, when using XmlUpdateRequestHandler , if I post a valid
command like "<commit/>" I get a response like

<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader"><int name="status">0</int><int
name="QTime">0</int></lst>
</response>

Nice, valid xml. But If I have an error (for example, <commit></comit>) I
get an HTML page back.

This tends to confuse the client software. Is there a way to get a return
like:

<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader"><int name="status">1</int><exception>blah, blah,
blah</exeption><int name="QTime">0</int></lst>
</response>


I've seen comments in solrconfig about setting handleSelect to true or
false, but didn't see any difference with either setting.

I've actually written my own handler, but since XmlUpdateHandler does the
same thing, I thought it would make a simple example.

Am I doing something wrong? Or is there some config I need to do, or is that
just how it is?

Tom

Re: Returning errors from request handler

Posted by Chris Hostetter <ho...@fucit.org>.
: > Is there a way to get a return like:
: >
: > <?xml version="1.0" encoding="UTF-8"?>
: > <response>
: > <lst name="responseHeader"><int name="status">1</int><exception>blah, blah,
: > blah</exeption><int name="QTime">0</int></lst>
: > </response>

see also SOLR-141 ... I'd really like it if eventually ResponseWriters
were delegatred to for formatting error messages in the appropriate
format, it's just never been a high priority -- but patches are always
welcome :)

https://issues.apache.org/jira/browse/SOLR-141

-Hoss


Re: Returning errors from request handler

Posted by Ryan McKinley <ry...@gmail.com>.
> Nice, valid xml. But If I have an error (for example, <commit></comit>) I
> get an HTML page back.
> 

In 1.2, if you map /update to the XmlUpdateHandler in solrconfig.xml, 
errors are returned with an HTTP status error (ie, something != 200) + 
message.  Your servlet runner (Jetty, Tomcat, etc) will format this as HTML.

> This tends to confuse the client software. 

Depends how the client is written ;)

The other option is to check the HTTP status on response.  It is nice to 
get a 400 when the input is wrong, a 401 if you are unauthorized to do 
something, a 500 is something went wrong on the server.


> Is there a way to get a return like:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <response>
> <lst name="responseHeader"><int name="status">1</int><exception>blah, blah,
> blah</exeption><int name="QTime">0</int></lst>
> </response>
> 

Yes, you can go back to solr 1.1 style response by removing the mapping 
for /update in solrconfig.xml

Check the last paragraph in "Upgrading from Solr 1.1"
http://svn.apache.org/repos/asf/lucene/solr/tags/release-1.2.0/CHANGES.txt


> 
> I've actually written my own handler, but since XmlUpdateHandler does the
> same thing, I thought it would make a simple example.
> 

Hymm, for your own handler... you could catch your own exceptions and 
put them in the response.  It was a design decision to only have 
response code 200 for valid responses and something != 200 for error cases.

ryan