Overriding app.ErrorMiddleware has no effect #1466
Comments
@devboy i tried to reproduce this with https://gist.github.com/paganotoni/a6d165e2a12447759cc9a68518b720a3 and it seems that i'm able to override the default error handlers even with GO_ENV=production. Instead of changing the ErrorMiddleware i'm updating the error handlers, would this strategy work for you?. |
@devboy can i know the reasons to override the ErrorMiddleware and why using custom error handlers wont work for you ? |
I don't understand the goal of if statement of app.go line 55 Line 55 in 78d649a
We just create "a" object (above lines 42-52) without setting ErrorMiddleware. As said in blog.gobuffalo.io (here section New Error Handling Middleware), it would be useful to take complete control over all of the error handling. But in fact, it's not that is currently implemented. If you're agree with that, let me know if you want that I submit a pull request. |
@sebd71 @paganotoni can you both review #1563 to fix this problem we have to introduce a breaking change in |
Fixed with #1564 ( |
Don't expose internal ErrorHandlers map and declare Get/Set methods to manage registered ErrorHandlers. - make ErrorHandlers Get function more robust (handle nil) - introduce Clear, Clone, Set and SetMulti functions - export DefaultErrorHandler function so that user can call it from its handler if needed be - add a new test to check Clear and SetMulti functions Change-Id: Ida701f6c6dea202db788f1dd805e2b7ccdff14cb Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Your changes introduce following problems / dangerous behaviors : 1/ you can create deadlock (forever loop)
2/ you can reset default handler unintentionally depending on the code order :
So make ErrorHandler private seems to me safest and expose (like you did in middleware) Get / Set functions to manage ErrorHandlers. |
Thanks for the feedback. I’m not convinced this needs the full rewrite you propose. The first issue can be fixed with a simple nil check. The second one is expected behavior. If I replace the whole ErrorHandlers with a new one, I would expect it to replace any previous changes I made to it. I need more convincing that the changes you propose are the right ones. |
I should also point out that you’re requesting breaking changes. I would recommend you open a proposal ticket and lay out your ideas there so the community can discuss the pros/cons of these changes. |
I have a buffalo.App for a JSON REST api.
Switching the
GO_ENV
toproduction
causes all errors to be sent as HTML.I changed the
app.ErrorMiddleware
to my custom one yet thedefaultErrorMiddleware
is still being called while the one I assigned is ignored.The text was updated successfully, but these errors were encountered: