How to handle 500 server errors in Umbraco - asp.net-mvc-4

I just want a custom error page when a server error occurs - I've tried endless combinations of suggestions that I've found on google but nothing even begins to get me there.
Essentially, I have some error handling routines in my surface controllers where I want to log the error & then throw the exception so that somewhere down the line a 500 response code is returned & a custom error page is displayed.
try
{
repository.AddShoppingCartItem(sci);
}
catch(Exception e)
{
Log.Error("whatever...");
throw;
}
Then in my web.config I've tried
<customErrors mode="On" defaultRedirect="error500">
</customErrors>
and
<customErrors mode="On" defaultRedirect="umbraco/surface/error500surface">
</customErrors>
(where the 1st version uses a regular controller & the second a surface controller)
Neither do anything.
I've also added this line as others have suggested but it makes no difference:
What I get is my normal layout page getting rendered along with this message:
Error loading Partial View script (file: ~/Views/MacroPartials/Addcart.cshtml)
what I want to happen is for a custom error page to be displayed instead.
Reading all the stuff on google, I'm completely confused as to whether I need to configure Umbraco to handle these errors or whether it's a pure MVC approach. I get the impression that 404 errors are done through umbraco but 500 errors need to be a pure MVC approach. Don't know if anyone can confirm this. Either way, something up the chain is swallowing my throw statement & I don't know what it is.
I've also tried
return new HttpStatusCodeResult(500);
in place of the throw & that just gets me a nasty IIS error page.
Any help would be most appreciated as this is driving me nuts.

500 errors are server errors and no different in Umbraco than in regular IIS:
This is a server error and can only be solved by website admin who has access to files and the web-server. There can be one of/or multiple reasons to get this error. One has to track down the issue and handle accordingly.
http://www.codeproject.com/Articles/545054/HTTPplus-plus-e-plusInternalplusserverplus
More info:
https://serverfault.com/questions/407954/how-to-diagnose-a-500-internal-server-error-on-iis-7-5-when-nothing-is-written-t
Edit: apparently you may be able to enable custom errors like so:
http://helpnotes.vpasp.com/kb/611-General-hosting-questions/1089-How-to-Turn-Off-Friendly-Error-in-IIS-7xx/
Edit2: This may be of interest as well:
http://benfoster.io/blog/aspnet-mvc-custom-error-pages

Related

How to catch exceptions thrown by UseDeveloperExceptionPage in asp.net core?

I'm using Dapper with a custom SqlMapper.TypeHandler for handling Uris. Whenever the Uri is not well-formed, the Parse method in the custom handler throws System.UriFormatException, which I expect to bubble up, caught by the UseDeveloperExceptionPage and displayed on the browser. But all I get is an empty page.
Looking at the VS stack trace, the following line seems to indicate the problem, but I don't know how to get around it:
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware: Error: An exception was thrown attempting to display the error page.
When I use my custom exception handler, app.UseExceptionHandler("error"), I'm able to display the error.
This is the only relevant discussion I could find, https://github.com/aspnet/AspNetCore/issues/3301, which was closed last year without a resolution.

cakephp 2 non existing controller and files could not be found

I make debug on a website running on cakephp 2 (yes it's old i know)
I have strange errors i cannot resolve.
in log i have:
-Error: [MissingControllerException] Controller class Wp-login.phpController could not be found
-Error: [MissingControllerException] Controller ColonisersController could not be found.
-Error: [MissingActionException] Action ImgController::ui-bg_diagonals-thick_90_eeeeee_40x40.png() could not be found.
-Error: [MissingActionException] Action ImgController::moustique-tigre-default.png() could not be found.
...
I search over all the source code for Colonisers but it is not write even once (also i think ColonisersController is a renammed controller because it is misspelled).
I search over the web for the Wp-login.php and it is a wordpress page, so no link to cakephp at all, also not write anywhere in the source code.
Same story for the missings pngs files. not in the source code.
I try to clear the cache folder on server but problems remains.
I have ghost source code? file are somewhere in another cache ?
any idea are welcomed.
By default all request that do not map to an actual file are being passed over to CakePHP, where the app will try to match the request to a route, and if one is found, finally try to match it to a controller and an action.
You seem to have some rather unspecific routes defined that eat pretty much anything as a possible controller name, hence things are being passed further for searching for a matching a controller and an action, which is where the request flow will end, as no matching controller or action can be found - consequently a MissingControllerException or MissingActionException is being triggered, an error is being logged (by default all exceptions are being logged), and in production mode (debug = 0) the app will respond with a 404 error.
So, no ghosts, no cached files, that's just how things work.

Pyramid Cherrpy blank error page

I have a small Pyramid application that by default used the waitress web server when I set it up. However I am now trying to switch to CherryPy since it works much better with sse.
But for uncaught exceptions I got a 500 error page with content in waitress, but using cherrypy the pages are just blank (the status is correctly 500 though).
The only thing I did to switch was to change the line:
use = egg:waitress#main
to
use = egg:pyramid#cherrypy
In the documentation for CherryPy I can read that I can set a custom error message for an unanticipated error. Tried that out but I saw no effect at all, the function is never called - I even tried to add a breakpoint to CherryPy's internal error response but it was not hit either.
I suspect something else is wrong though since I assume CherryPy should show "something" by default for a 500 page ?
I have attempted to reproduce the issue using the starter scaffold that comes with Pyramid, and made the following modification to the existing views.py that it comes with:
from pyramid.view import view_config
from pyramid.httpexceptions import HTTPInternalServerError
#view_config(route_name='home', renderer='templates/mytemplate.pt')
def my_view(request):
raise HTTPInternalServerError()
On both CherryPy and waitress this returns a page with the HTTPInternalServerError() on it including the text.
Changing the raise to:
raise ValueError('test')
However only shows something on the page if the pyramid_debugtoolbar is enabled, and the user accessing the URL is allowed to see the pyramid_debugtoolbar (this is controlled by the hosts setting for pyramid_debugtoolbar).
CherryPy does not have its own text. Unfortunately I don't see a way to use the _cp_config method of enabling custom error messages, as there is no way to set it up on the HTTP server that is used when using the CherrypyWSGIServer which is used by the Pyramid cherrypy entrypoint used by pserve.
What you can do, is set up a default exception view in Pyramid such as the following:
#view_config(context=Exception)
def exception_view(request):
request.response.status = 500
request.response.text = u'Something went very wrong. Sorry!'
return request.response
You can off course customise this exception view however you'd like. If this exception view raises however, you will be at the mercy of CherryPy who will serve you a blank page.

How to show error pages in MVC if error occurred in different project

My MVC application uses error pages, configured in the web.config file. All errors display a single web page, regardless of the type of error. This works fine.
The problem I have though, is the exception isn't thrown in the web project, but in my BLL project. So, consider this
//My Web.Ui
public ActionResult Thing()
{
Bll.Statics.DoThis();
return View();
}
and my BLL is
public static void DoThis()
{
throw new Exception("Kaboom");
}
The problem is, when the error occurs here, I don't see my 404 page, I get a standard 'browser' error page explaining something when wrong.
Do I simply just need to wrap all calls in Try Catch from my Controllers so I can throw (re-throw) the exception from the controller itself?
Yes, wrap all your calls in a try-catch block. On the other hand think about the exceptions that you might be catching. Do you want to catch Exception or you want to give different information, like in case of SqlException when you don't have connection to the database, etc. If all you want is to show your custom 404, then you might go with a generic option.

Why are xforms-submit-error event properties allways empty?

I've just started with orbeon and xforms for some project.
I have Orbeon succesfuly integrated with my test application as xforms engine (separate deployment with crosscontext).
Now, xforms basics are behind me and I needed to implement some kind of error checking after submit. So I'm trying to handle xforms-submit-error for example like this (this is modified example from w3.org):
<xf:submission action="/processor500" method="post" id="submission1" replace="none">
<xf:message ev:event="xforms-submit-error" level="modal">submission1 error (<output value="event('response-status-code')"/>)</xf:message>
</xf:submission>
/process500 is empty servlet, which just raise RuntimeException so it is returning 500 response code.
But response-status-code in event is allways empty. Any of event properties are allways empty and i just can't figure it why (google didn't help this time).
Any suggestions?
Thanks.
event('response-status-code') on xforms-submit-error is supported, and your example doesn't work most likely because you're missing a prefix on the <output> (it should be <xf:output>). Also see this XForms test case showing the event('response-status-code') in action.