I hope someone can assist with this problem.
I've got a web services app I'm writing in rails. I'm using RocketPants for the services and Authority for the authorization.
I've run into an issue with exception handling where the Authority "that's now allowed" exception (Authority::SecurityViolation) is rendering as HTML, rather than JSON.
I've documented the story in this gist and this issue.
I can replicate by raising an exception within my ApiController like raise "blah", and I get a html error page. I've tried using rescue_from like in this question with the same unsuccessful result.
I don't know where to from here. Anyone know of anything in the Rails exception handling stack that causes this? I'd be grateful for any assistance.
Did you tried this in your ApiController class ?
rescue_from StandardError, with: :render_unknown_error
def render_unknown_error(error)
render(json: error.inspect, status: 500)
end
Related
Do exceptions that are filtered with a custom ExceptionFilterAttribute logged to Application Insights?
I want to return a custom DTO in my custom ExceptionFilterAttribute filter, but I think exceptions are no longer logged into ApplicationInsights after that. This is for .NET Core 3.0.
I added a line with:
this.telemetryClient.TrackException(context.Exception);
to make sure I can see the exception but I'm not sure if my exceptions are logged twice now.
Does anyone know if ApplicationInsights will log exception if they enter ExceptionFilterAttribute? I can't find documentation for this.
I'm calling just in case also:
base.OnException(context);
Does anyone know if ApplicationInsights will log exception if they
enter ExceptionFilterAttribute?
Yes, it will log the exceptions, so you do not need to add this line of code this.telemetryClient.TrackException(context.Exception);. Just using base.OnException(context); is ok.
You can see this GitHub issue for the similar issue, the reason is that "With new Ilogger enablement by default, exceptions are automatically reported by application insights.".
I also check it via a simple test, the test result as below:
We are using the MSXML2.ServerXMLHTTP60Class to make HTTP requests. Usually this works fine, but on some occasions when the url cannot be resolved, the send method fails. In this case an exception is thrown.
The problem is that we program in Microsoft Dynamcs NAV C/AL code. This language does not support error trapping (try catch).
Does anybody know if there is some setting in the ServerXMLHTTP60Class that prevents the send method from failing?
Note: the send method fails, so checking the response status is not an option.
Thank you!
Depend your on version of Nav you have different ways to handle exeptions.
In Nav 2016 there will be try function
In previous versions you should use if codeunit.run then syntax to catch the exception and getlasterrortext to get error message.
For more information read Vjeco
Another option to avoid unhandled exceptions is to write a wrapper class around ServerXMLHTTP60Class that will catch all exceptions and handle them in the way you like.
I am using Rspec 2 and capybara and defined the basic integration test, i.e.
describe "EeRequisitions" do
describe "GET /ee_requisitions" do
it "works! (now write some real specs)" do
get ee_requisitions_path
response.status.should be(200)
end
end
end
Since the app uses HTTP basic authentication and since capybara says it includes Rack::Test, I expected that adding the line:
authorize 'user', 'password'
would handle it (I've since lost the stackoverflow post that told me that). Unfortunately it didn't - it kept throwing a 'method not found' error. I finally found the solution in a comment to this post: Rails/Rspec Make tests pass with http basic authentication where Matt Connelly pointed me to this gist: https://gist.github.com/mattconnolly/4158961 which finally solved my problem.
However, I'm still wondering why the Rack::Test approach failed as it seems to have worked for others.
Does including the line
include Rack::Test::Methods
at the top of the tests make a difference?
I have a Rails 3 app that is using the exception_notification gem to send emails about exceptions.
I would also like to show users specific error messages when exceptions occur, but by catching a generic Exception because I'm not sure of all the exceptions that can occur. I'm thinking the way to do this is to rescue from Exception, and then raise a custom exception. That way I'm still getting an email about the exception, and the user can see the custom exception's error page.
Does this sound like a Rails 3 way to do things?
Thanks a lot.
I think not.
As Ryan Davis says
Don’t rescue Exception. EVER. Or I will stab you.
More info about that statement here.
Rails 3.2 does exception handling in two middlewares:
ActionDispatch::ShowExceptions
ActionDispatch::DebugExceptions
You can check that one by running
$ rake middleware
ActionDispatch::ShowExceptions [source]
Used in production to render the exception pages.
ActionDispatch::DebugExceptions [source]
Used in development environment to render detailed stack traces when exceptions occur. Stops the middleware call chain and renders the stack trace if action_dispatch.show_detailed_exceptions is true to be more precise.
So the most simple way of doing something normal with this middleware would be monkeypatching the call method of ActionDispatch::DebugExceptions, doing all you need to do and then calling the original method.
The better way of doing this is, however, including your own middleware between those two. In it, you would wrap the call inside a rescue block and do your custom processing.
I am a maintainer of Airbrake and this is exactly what we're doing right now.
You might also want to check Errbit, the self-hosted alternative.
I am using client response interface of apache abdera. I want to see what data the server returns me in the response object. I tried using the getDocument() method of response object but it throws me an exception as follows:
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.axiom.om.util.StAXUtils.getXMLInputFactory(Lorg/apache/axiom/om/util/StAXParserConfiguration;)Ljavax/xml/stream/XMLInputFactory;
at org.apache.abdera.parser.stax.FOMParser.getXMLInputFactory(FOMParser.java:152)
at org.apache.abdera.parser.stax.FOMParser.createXMLStreamReader(FOMParser.java:178)
at org.apache.abdera.parser.stax.FOMParser.parse(FOMParser.java:143)
at org.apache.abdera.protocol.client.AbstractClientResponse.getDocument(AbstractClientResponse.java:111)
at org.apache.abdera.protocol.client.AbstractClientResponse.getDocument(AbstractClientResponse.java:89)
at org.apache.abdera.protocol.client.AbstractClientResponse.getDocument(AbstractClientResponse.java:71)
Does anyone know a way to read the conents of response object?
Thanks
I've faced the same problem under different circumstanes. After some investigations I've found out, that problem is in wrong compile-time/runtime Axiom version (1.2.5 vs 1.2.10);
Filed
https://issues.apache.org/jira/browse/ABDERA-284
I've attached proposed fix (ABDERA-284-fix.diff), that worked fine for me to the bug.