Unable to catch exception in exception strategy Mule ESB - exception

Am getting the below error in the http connector,I need to catch the exception and perform an operation
org.mule.module.http.internal.request.ResponseValidatorException: Response code 503 mapped as failure. Message payload is of type: BufferInputStream
Below is the code i have written inside choice exception
<catch-exception-strategy when="#[exception.causedBy(http.internal.request.ResponseValidatorException)] " doc:name="ResponseValidator Exception Strategy">
But the catch block is not catching the exception

check the root exception message by using #[groovy:message.getExceptionPayload().getRootException().getMessage()]
in default exception block and fetch the root exception details and use it in your choice exception strategy

Related

Suppress timeout exceptions in EF Core request by own try-catch?

I'm using EF Core 6 in a .NET 6 project.
Some of my SQL requests leads to a SQL Server timeout. This is not a big deal and I want to catch this exceptions to just produce a warning instead of an error in the logs.
try
{
List<SomeClass> results = dbContext.TableName
.Where ....
.ToList();
}
catch (Exception ex)
{
// log some warning ...
}
The exception is caught and the warning is logged.
BUT: additionally the EF call itself produces an error that is logged/printed out in console.
How can I suppress the exception within the EF database request to let "my" catch be the only one to handle all exceptions?

Actual exception is not getting logged in MVC when host in IIS

I am running one MVC application where i found one exception in specific method. I will provide here complete details about it.
I am loading some third party grid control from view. to load it i used below code:
#{Html.RenderAction("MasterGridAction", "MyController");}
Now when i access this report from development then this view load and it hits this action method where i used some piece of code there it is throwing error, To catch the error i used try catch block in the method where in catch section i used below code to throw the actual exception like below:
catch (Exception ex)
{
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(ex).Throw(); throw;
}
When exception get catched it sends this to the Application_Error method in global.asax page where i used below code to find out the actual exception like below:
void Application_Error(object sender, EventArgs e)
{
HttpServerUtility server = HttpContext.Current.Server;
if (server.GetLastError() != null)
{
Exception exception = server.GetLastError();
if (exception.GetBaseException() != null)
{
exception = exception.GetBaseException();
ExceptionType(server, exception);
}
else
{
ExceptionType(server, exception);
}
}
}
In this ExceptionType method i get the exception stack and log to the file using "Log4Net". After logging to the file i could see the exception in notepad like below:
Object reference not set to an instance of an object.
Source File: /MyController/MasterGridAction
Stack Trace:
at 3D.Controllers.MyController.MasterGridAction() in D:\MyUser\3D_MVC\Application\3D_OnlyRelease\3D\Controllers\MyController.cs:line 405
--- End of stack trace from previous location where exception was thrown ---
As we can see in above exception it is clearly shown the line number also where this exception get caught.
But once i host this application in IIS server and access the same page then i could see the logged file
There it shows exception like below:
Exception Message: Object reference not set to an instance of an object.
Stack Trace: at 3D.Controllers.MyController.MasterGridAction()
--- End of stack trace from previous location where exception was thrown ---
As you can see the logged exception of IIS server is not having much information when compare to other exception details.
Am i missing anything there to get the complete exception when host in IIS?
Please suggest.
As you can see the logged exception of IIS server is not having much information when compare to other exception details.
This could be because you don't include the PDB files in production.
It might not be a great idea to include them, since that way one can reverse engineer you app with more precision if they hack your server, but it is up to you to decide. I have seen organizations that include them in their production environments.
Try publishing and deploying on a test environment with and without the PDB files to verify this.

Throw unauthorized exception to be caught by UseStatusCodePagesWithReExecute

I have setup UseStatusCodePagesWithReExecute in asp.netcore website and it works fine.
I'm now trying to manually throw an error and I would like UseStatusCodePagesWithReExecute to catch it automatically but not as a 500 but as a 401 !
What type of exception should I throw?
If it's not possible, I guess I will have to create my custom middleware. In that case, how do I redirect from it in case I have this exception?

Get the true exception class from asmx web service using MSTest

So I have this web service that I am testing using MS Test and I want to get the original exception class which is InvalidOperationException. However whenever I run my test, the exception that I get is the FaultException class (which is the default exception when consuming a web service). I only get the exception in the message property of the exception.
Below is the exception message that I am getting.
`System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: Invalid Entity\n at BL.Lib.WebService.BLWebServiceImpl.UpdateIDNumber(GetUpdateIDNumberRequest idNumberRequest) in [some file]:line 369\n at SSMWebService.Blacklist.BLWebService.BlacklistUpdateIDNumber(GetUpdateIDNumberRequest request) in [some asmx file]:line 132\n --- End of inner exception stack trace ---
Is there a way to get the InvalidOperationException class from the web service?

How to stop handled Exceptions from being logged?

I have just implemented exception handling for a unique-constraint of a JPA entity. It is working as I want it to, but when triggered dumps the handled exceptions to the container logfile.
A JPA entity is managed by a SLSB (Service Façade). The Service Façade is called from another SLSB, which provides remoting capabilities based on JAX-RS.
In the Service Façade, the EntityManager operations are wrapped in a try-catch-block, detecting the cause of the unique-constraint-violation. It then throws a custom checked ApplicationException.
The REST-Bean catches the ApplicationException and throws a custom unchecked BadRequestException.
An ExceptionMapper outputs the BadRequestException to the remote client.
This is all working well. The part that I don't understand is: the (handled) exceptions get logged in the container's logfile (complete with a long stacktrace):
[#|2010-09-29T18:49:39.185+0200|WARNING|glassfish3.0.1|org.eclipse.persistence.session.file:/Users/hank/NetBeansProjects/CoreServer/build/classes/_coreServerPersistenceUnit|_ThreadID=30;_ThreadName=Thread-1;|
Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry....
....
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry....
and from throwing the BadRequestException:
[#|2010-09-29T18:49:39.336+0200|WARNING|glassfish3.0.1|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=30;_ThreadName=Thread-1;|A system exception occurred during an invocation on EJB ShopperResource method public javax.ws.rs.core.Response mvs.gateway.ShopperResource.create(javax.xml.bind.JAXBElement)
javax.ejb.EJBException
at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5119)
....
Caused by: mvs.api.exception.BadRequestException: mvs.api.exception.MvsCause: Field 'MSISDN' must be unique!
Is this how it should be? I thought since I handle the exceptions, they wouldn't be dumped to the log?
The exceptions are logged because you have exception logging enabled.
Exceptions get logged by default when your log level is WARNING or greater. If you set your log level to SEVERE or OFF then they will not be logged.
i.e.
"eclipselink.logging.level"="SEVERE"
You can also set the "eclipselink.logging.exceptions"="false" property to disable just exception logging.
See,
http://wiki.eclipse.org/EclipseLink/Examples/JPA/Logging
It's the database layer that does the logging of the exceptions. The time you catch them they are already written to the log.