quirkey/sammy

Sammy breaks window.onerror

blyndcide opened this issue · 3 comments

I am attempting to use window.onerror to log errors to a server. Unfortunately Sammy is causing wrong parameters to be sent to the handler. window.onerror handler expects function(errorMsg, url, lineNumber) string, string, int.

If an error happens inside a Sammy route, (jQuery.Event, Object, undefined) is sent to the handler. Sammy's error method uses jQuery's trigger to fire the error event. It would seem using trigger to fire an error event that will be caught in window.onerror is bad for the same reason jQuery documentation says not to use $(window).error. See last paragraph at http://api.jquery.com/error/.

Also Sammy's error method causes the window.onerror function to run multiple times when a single exception is thrown.

+1

Sammy first catch route error and create error object and throw it so if you are using window.error method , it will except a string but you will get a object and the problem will come when you try to stringify that obj to send to server.

the best way to handle this is overright error method of sammy and deal with that. you should use something like this in your sammy app.

app.error =function(message, original_error){

 console.log(message);
 throw new Error(message);  // this will be catched by your window.error method.

}

Thanks