Harald Kirsch wrote:
> Hello,
>
> can anyone shed some light on best practices for handling errors when
> creating a resource.
>
> My application provides for the upload of some data which results in the
> creation of a new resource. If the uploaded data is malformed, I want to
> display the main application page, but with an additional error message.
> How is this normally implemented?
>
> Ideally I would like to just call the resource method to create the main
> resource while providing some error information to render. But how would
> I instruct the browser that what it is getting is no longer the upload
> resource, but the main page. I tried setting the location header, but at
> least firefox 2 ignores this and keeps showing the upload-URL it
> originally requested.
>
> If, instead, I send a redirect to the browser, how should I preserve the
> error information to be picked up by the redirected resource?
>
I am not sure that having the error information associated with the
resource state is a good idea. As the state of that resource requires
updating with error information specific to a previous request. I guess
it depends if you want to log the errors as state that can be exposed as
resources.
Alternatively an error processing a POST/PUT request could result in a
response with an error status code 400 (Bad Request) in the response
with the error information in HTML of what went wrong. In JAX-RS you
would throw an exception and map that exception to a response or
directly throw a WebApplicationException. Links in that HTML could take
the user to the main page or to retry the upload.
Paul.
> Thanks,
> Harald.
>
--
| ? + ? = To question
----------------\
Paul Sandoz
x38109
+33-4-76188109