[Proto-Scripty] Re: What's your favorite error status code?
Walter, What I do in those case is: - Returning my own error code in a JSON's attribute (lets use myJsonStatus for the example) - Use AJAX.Responders to override onCreate to wrap the provided onSuccess into a custom function which checks responseJSON.myJSONStatus and do appropriate processing if present or call provided onSuccess handler if it is not. I only use this for unrecoverable errors but I guess you may provide to your Ajax.Request custom handlers like onMyPrivateAppStatusUserDidSomethingWrong and call it if your myJsonStatus is 'UserDidSomethingWrong' (you may of course use numerical codes, but example is then less funny :o) ) (untested) implementation: Ajax.Responders.register( onCreate: function(r) { r.options.onSuccess = (r.options.onSuccess|| Prototype.emptyFunction).wrap(function(localCB,xhr,xjs){ var js = xhr.responseJSON || {myJsonStatus:'MalformedJSON'}; if(js.myJsonStatus){ (r.options['onMyPrivateAppStatus'+js.myJsonStatus]|| Prototype.emptyFunction)(xhr,xjs); } else { localCB(xhr,xjs); } }); }); usage: new Ajax.Request('myAjaxScript.php',{ parameters: {'whatever':'is needed here'}, onSuccess: function () {...}, onMyPrivateAppStatusUserDidSomethingWrong: function() {...}, onMyPrivateAppStatusMalformedJSON: function() {...} }); Eric On Jul 7, 2:27 pm, Walter Lee Davis wa...@wdstudio.com wrote: On Jul 7, 2011, at 8:21 AM, T.J. Crowder wrote: To my mind, HTTP response codes aren't for application logic signalling. They're for signalling between the browser and server. The correct response to bum data from the user is a 200 with an application-logic-level success/error flag. Fair enough, but since the onFailure callback only runs if the response code sent back is something other than the 200 range, how would you recommend I send back that failure other than with the status code? Walter -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
[Proto-Scripty] Re: What's your favorite error status code?
On Jul 7, 12:42 pm, Walter Lee Davis wa...@wdstudio.com wrote: I've used 409 (Conflict) a lot to signal back to my application that an Ajax request went wrong at the server level (409 and Ajax are both powerful household cleaner brands, so it's my private-joke-over-HTTP status). But if I want to be semantic at the error code level, what code best signals you, the user, did something incomplete or wrong, so you are not getting a 200 for your effort? Thanks, Walter To my mind, HTTP response codes aren't for application logic signalling. They're for signalling between the browser and server. The correct response to bum data from the user is a 200 with an application-logic-level success/error flag. I wouldn't conflate the transport and business logic layer errors. (The 409 / Ajax thing *is* funny.) FWIW... -- T.J. Crowder Independent Software Engineer tj / crowder software / com www / crowder software / com -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
Re: [Proto-Scripty] Re: What's your favorite error status code?
On Jul 7, 2011, at 8:21 AM, T.J. Crowder wrote: To my mind, HTTP response codes aren't for application logic signalling. They're for signalling between the browser and server. The correct response to bum data from the user is a 200 with an application-logic-level success/error flag. Fair enough, but since the onFailure callback only runs if the response code sent back is something other than the 200 range, how would you recommend I send back that failure other than with the status code? Walter -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
[Proto-Scripty] Re: What's your favorite error status code?
On Jul 7, 1:27 pm, Walter Lee Davis wa...@wdstudio.com wrote: On Jul 7, 2011, at 8:21 AM, T.J. Crowder wrote: To my mind, HTTP response codes aren't for application logic signalling. They're for signalling between the browser and server. The correct response to bum data from the user is a 200 with an application-logic-level success/error flag. Fair enough, but since the onFailure callback only runs if the response code sent back is something other than the 200 range, how would you recommend I send back that failure other than with the status code? Walter Let's just say I never use Ajax.Request directly. :-) I put in application-level plumbing and take care of things like providing a `context` parameter for callbacks and handling both transport and application logic errors. -- T.J. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.