grails and debugging UrlMappings - grails

In grails, how can I add some code to the UrlMappings.groovy (ex: println) so that I can figure out what the request URI is and which mapping is getting hit (if any)?
Background:
In this situation, there are two servers which serve different things based on file extension. So, the two servers need to always see file extensions for error processing to continue. Otherwise, the servers get confused and 1 serves up a 404 page instead of our 500 page.
The bigger picture involves taking a 500 response due to something like a NullPointerException and tracing it through the code to see what is happening.
I added code like the following which is at http://jetlet.blogspot.com/2010/08/grails-exception-handling-with-response.html :
"500" (controller: "error", action: "internalError")
In testing this, I am throwing a NullPointerException (NPE) on purpose. The 500 handling is called and 500 page is served up when entering in the URL into the browser's address bar. However, when posting a form to the server and having the processing code blow up on purpose with a NPE, the "500" handling code does not get called. The URL in the form's action seems to end with an extension. So, not sure why the difference in behavior between the GET (browser URL) and POST (form submission).
Thanks for insights and thoughts on tracking this down !

In your Config.groovy you can modify your log4j settings for url mapping events by adding
all 'org.codehaus.groovy.grails.web.mapping'
to your existing log4j settings. all is the most verbose setting so it can be tuned back if that starts giving you too much. You can find more information in the official grails documentation here : http://grails.org/doc/latest/guide/3.%20Configuration.html

Related

How can I display a custom error page with Ruby on Rails in any failure case?

I know that if an exception is raised in my main app, I can use the exceptions_app configuration attribute to serve a dynamic error page.
However, if this error page is dynamic, it might also fail. In my case, I'm sharing some of the display logic with the main app, and it happened that that logic was the source of the exception, and rendering the error page raised it again. My end users then saw the Passenger error page, which is all purple and weird and frightening.
How can I reliably display a custom error page to my users, possibly with a static page fallback?
There is actually a whole series of configuration switches and redirection possibilities depending on your stack.
Here is a decision flow diagram showing all the possibilities. If you have a dynamic error page, you should really also add a static rendering of it in public/500.html, and symlink it to some other file and reference that one in your web server (in the diagram, Apache’s ErrorDocument).
You cannot simply serve public/<HTTP status code>.html directly. Indeed, the web server would then consider /<HTTP status code> requests as requests for the static page, and our errors controller would not trigger Rails routing anymore, preempting dynamic errors display.
You should set config.action_dispatch.show_exceptions to false (more details), as well as disable your app runner (Passenger in the diagram) error page, otherwise you will leak exceptions content.
If you want to go to that level of detail, it is very important that you add integration tests on a user-hidden, voluntarily broken page, as you are disabling some debugging and failsafe features.
References
You could also be interested in the following references:
Base tutorial for dynamic error pages in Rails.
If you want to use your main app to display errors.
CustomErrorsHandler is a gem that automatically tries to use <HTTP status code>.erb templates and falls back to static public/<HTTP status code>.html pages.
How to render a static version automatically by precompiling Rails Static 404 and 500 Pages.

How to solve the 500 Server error in asp.net mvc without enable the error show stuff

I am using asp.net mvc 4 for my project. my project is going well. I wonder about a thing.
I make a controller Test and ActionResult Index() this action doesn't need any viewdata or any kind of things.
Now When I test it in my local computer it's should work and it is. no problem.
Now amazing thing is it's doesn't work on server.
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.
I am amazed that what happen to my code when everything work without any exception.
Now when I told other people about log they don't have anything. I don't want to install any nuget package on live site to test it. Do someone help me to solve this without adding any error checking module.
How I can check the issue on server.
IIS will log 500 errors in the Event Logs. So assuming you have access to the server, you can check there.
Well, I'm sorry but you have to be willing to do something... If you don't want to install packages like Elmah or enable remote iis debugging or etc... the only other thing that comes to my mind is for you to just start changing random stuff and hope it works. Also, most of these 500 internal server errors are caused by something in the web.config file. Make sure everything is set and good in there.
A very common reason for getting 500 Internal Server error is : Issue in Web.Config file.
Many times one can have some tags not closed properly OR missing Double quotes etc..
In general some syntax error is present most of the times in Web.Config. So make sure atleast you PASS this case.

MVC.Net site is throwing a 404 error for a resource/page that isn't being called

Ok, this one is killing me. It makes no sense at all... I've setup a simple MVC.Net project. Everything appears to work fine. I get the typical 404 errors, and wanted to change that so I started looking into that... That got me poking around in the Application_Error method in the global.asax. It all appears to work as I would expect.
Here's the problem. I put the following line of code (just this line) in the Application_Error method and made a breakpoint to see what the error traffic was like so I could test things, etc.
Exception ex = Server.GetLastError();
I'm running the project in debug, and it comes back with an HttpException with an error code 404
The controller for path
'/Content/jquery-ui-1.8.7.custom.min.js'
was not found or does not implement
IController.
So far nothing too strange, right? So, I did a search for this offending call. I used the Visual Studio Find function and searched Entire Solution for /Content/jquery-ui-1.8.7.custom.min.js. There were no calls to this file. I searched for jquery-ui-1.8.7.custom.min.js and found all the expected calls to that file which look for it in the /Scripts/ directory.
In the /Content/ directory I have my .css files, and some images in the Images subdirectory...
I'm hoping there is just something strange that I don't know about with MVC.Net that you guys have already figured out that causes this quirkiness. It just makes no sense... I could see getting the 404 if there was a call to that file, but there isn't...
Any guidance on even some troubleshooting ideas would be helpful at this point. I'm stumped...
Thanks guys!
Just a suggestion to help you debug: Download Fiddler and check the actually HTTP requests being made. Note: When debugging using localhost, make a new hosts entry and point 127.0.0.1 to some other name, otherwise Fiddler won't track the requests.

how to handle errors like 404 / 500 in rails3

Hey, I hope you can help me.
I am trying to find a way to direct the user to the default error pages 404.html and 500.html in my public folder.
So when there is a routing or nomethod error it should be directed there to.
I already tried some stuff in my application controller but it didnt work.
Many thanks!!
Rails does this for you automatically when running in production mode. When you upload your application to a live server, Rails takes care of handling those exceptions and rendering the correct error pages with the correct header status. If you're trying to see what those pages look like (for testing or something), just access them directly via http://localhost:3000/404.html
Whenever you set up your Rails application on a live server (let's use Apache as an example), you give the site root as the /public folder in your application. Then, whenever a request is made to that server address, Apache first looks in that public folder and tries to serve a static asset (this is a configurable option in [environment].rb). If it can't find the requested page, then the request is forwarded through the Ruby stack.
When in production mode, if Rails encounters an error that isn't handled (i.e begin, rescue), it throws the error the whole way up to the stack, which then tells Apache (again, in my example) to render an appropriate error.
Here are some common errors that you'll see in development mode and what they render in production mode:
ActiveRecord::RecordNotFound => 404 (page not found)
nil.method => 500 (server error) unless you turn off whiny nils
ActionController::RoutingError => 404 (page not found)
Happens automatically if run in production mode - no need that you do that manually.
Have a look at this post to redirect all requests causing a Routing Error.

Any ideas how to troubleshoot HTTP Error 400 for MVC/Firefox?

Two clients complains on HTTP Error 400 from Mozilla Firefox 3.6.9. This happens when they open any link - both mvc application and also any static images, which are hosted on Classic application pool without any code.
Exact error message is HTTP Error 400. The request is badly formed
No errors in windows log and application error log. Proxy in browser is set to off.
Other browsers works fine for them.
Any ideas about what could cause such behavior?
For now, i can see only one option - ask them to install Firebug, but this is not really user friendly.
For some reason, cookies was corrupted and this was leading to HTTP 400 error.
After user cleaned cookies for this website he was able to get page.
I still need to investigate what exactly went wrong and find source of this problem but it is clear that I need to review all places where I do cookie creation.

Resources