Created by @Yess in Q&As
@Yess
@Yess

Hi, i'm currently trying to render 404 page after BadRequestException is thrown from presenter.

The snippets were sent correctly, but as soon as there is a 404 or some other error code, nittro is just ignoring them.

@jahudka
@jahudka

Hi, yes, any request which results in a HTTP status code >= 400 is considered an error, so the transaction will fail and Nittro won't apply any snippets from the response. You can update your error presenter to send a HTTP 200 if the request has been made using AJAX; that'll help. Obviously an argument can be made that the server should always use the appropriate HTTP code when responding to a request and that Nittro should honour the payload instead of strictly checking the response code - and Nittro 3 will probably behave that way - but since this could potentially break things for people I don't think it'd be wise to change this behaviour now.

@Yess
@Yess

That's what I did as quick fix .. so no other work needed for now :) .. thx for quick response.

@Yess
@Yess

There's still one problem connected with this behaviour:

When I'm trying to delete some resource (while using dynamic snippets):

  • Nittro prevents me from rendering flash with error message while there's an error response (4xx)
  • on the other side, when I use response code 2xx dynamic snippet is automatically removed even if it's still in list (not really deleted)
@jahudka
@jahudka

You're right - this whole thing is part of a larger problem that I'm hoping to solve in v3 - how to differentiate a successful request from an unsuccessful one - this has implications for many different Nittro components and snippets are no exception. Obviously one way to do this is use proper HTTP status codes - and if I don't find a strong enough reason not to then Nittro 3 will use them.

For now - I imagine that in the delete handler you probably have access to the object the snippet represents during the attempted delete operation - so if the delete fails for some reason, you can just render the snippet again (redrawing its container) - on the frontend this will result in the original element being removed and a new one being inserted, so provided you specify a suitable sorting rule you can have it appear that the snippet didn't vanish at all.

Sign in to post a reply