Persisting State Across Server Restarts

31 views
Skip to first unread message

James Muerle

unread,
Mar 29, 2016, 4:53:28 PM3/29/16
to Lift
Hi community,

I've been working on a project where we're trying to solve the following problem:

A user is on our site, filling out a form. While they are doing so, we restart our server with an update. When the user submits the form (through liftAjax), they get an unmapped parameter exception.

Our current working solution is to record the actions the user takes on the page (client-side) until we detect an unmapped parameter, and then refresh the page and re-perform the last action taken. To preserve the state of any fields on the page, we will be pushing data onto the window history. The problem I've found, though, is that I'm not able to tell the client side through a response that we had an unmapped parameter on the server side. The handleUnmappedParameter LiftRules vendor does not allow for a return type, so the only thing it can do is redirect the page with S.redirectTo or with a ResponseShortcutException. Is there a way to give a special response to the client in the case of an unmapped parameter? Is there entirely another way that I should be solving this problem?

Thanks for all of your times,
James

Antonio Salazar Cardozo

unread,
Mar 29, 2016, 5:24:38 PM3/29/16
to Lift
The nice thing about ResponseShortcutException is that it allows you to
return an arbitrary response. So you can also return a JavaScriptResponse:

throw ResponseShortcutException.shortcutResponse(
  JavaScriptResponse(Call("reloadAndDoMagic").cmd)
)

That should run reloadAndDoMagic() on the client as a response to
the unmapped parameter.

Does that help?
Thanks,
Antonio

James Muerle

unread,
Mar 30, 2016, 3:00:27 PM3/30/16
to Lift
Yeah, I saw that I could return an arbitrary response, so I tried to return a JsonResponse, but I was getting a server 500 error. I switched to using your code and I'm getting the same thing. Let me know if that's expected, because I'm assuming at the moment that we are somehow catching the exception by accident. It's weird, though, because S.redirectTo is working just fine, and as far as I know that uses ResponseShortcutException as well.

By the way, thanks for the prompt response!
James

James Muerle

unread,
Mar 30, 2016, 6:05:02 PM3/30/16
to Lift
After a bit of investigation, I've found the minimal change that would cause the problem I'm encountering.

ResponseShortcutException has three arguments: Response callback, Redirect address Box, and a notify boolean. No matter what the response is, it seems that the ajax call will result in a 500 if the redirect box is Empty, and otherwise result in a success with the js response of "\nwindow.location = 'your string';". That is why S.redirectTo was working as intended, but when I tried making my own response it wouldn't work.

We are currently on Lift version 2.6, and it looks like this issue was addressed here: https://github.com/lift/framework/issues/1638.

Thanks for all your help,
James

Antonio Salazar Cardozo

unread,
Mar 31, 2016, 12:11:08 AM3/31/16
to Lift
Nice find! I confess I'd completely forgotten about that issue and its
fix. Glad you figured out how to get it done even on 2.6 :)
Thanks,
Antonio
Reply all
Reply to author
Forward
0 new messages