Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor exception handling, rendering, and reporting #1641

Closed
4 tasks done
tobyzerner opened this issue Nov 13, 2018 · 8 comments
Closed
4 tasks done

Refactor exception handling, rendering, and reporting #1641

tobyzerner opened this issue Nov 13, 2018 · 8 comments
Assignees
Milestone

Comments

@tobyzerner
Copy link
Contributor

tobyzerner commented Nov 13, 2018

From #1633 (review):

What I would like to see in beta.9:

  • One middleware (always enabled) that converts all known exception types with custom views to pretty error pages, always.
  • Another middleware (either Whoops or pretty pages) that a) displays the exceptions and b) logs them. (The logging could even be a separate middleware that re-throws the exceptions, unless that messes with the stack traces.)

IMO, there is no need for NotFound and similar exceptions to ever be handled with the fallback error handling (Whoops or pretty pages) - we are just using the exception mechanism to handle known error cases.

May be worth taking some inspiration from https://laravel.com/docs/5.7/errors

I would also like to see the ability to configure logging - we may as well make use of the power of Laravel's logging component.


Step-by-step TODO:

@tobyzerner tobyzerner added this to the 0.1.0-beta.9 milestone Nov 13, 2018
@luceos
Copy link
Member

luceos commented Nov 13, 2018

One thing I think is a must-have is the ability to easily enable Sentry. This would especially be helpful for taking immediate action when encountering unexpected errors on discuss. I will gladly provide an extension if need be.

@franzliedke
Copy link
Contributor

I'd be most interested in your opinion on this:

IMO, there is no need for NotFound and similar exceptions to ever be handled with the fallback error handling (Whoops or pretty pages) - we are just using the exception mechanism to handle known error cases.

@luceos
Copy link
Member

luceos commented Nov 15, 2018

Catching NotFound exceptions allows for customising the returned response, eg with a decent error page or through extensions to list related discussions. Unless of course an extension could be configured to handle an uncaught exception (add to the handler stack, I think this is currently the case).

I would be very interested to know whether we can create decent error pages for any HttpException (with 500 probably being the 'exception').

@franzliedke
Copy link
Contributor

@luceos Yes, I want to keep that part. My question was about the Whoops error page, which is currently shown (in debug mode) for NotFound exceptions and the like. IMO, these exceptions should always be handled by the error handler stack.

Debug mode (a.k.a. Whoops error pages) would then only have an effect for generic 500 errors.

@luceos
Copy link
Member

luceos commented Nov 15, 2018

My question was about the Whoops error page, which is currently shown (in debug mode) for NotFound exceptions and the like. IMO, these exceptions should always be handled by the error handler stack

When in debug mode you should always be able to get as much information as possible immediately (without diving into logs). I can imagine it would be easier to identify the cause of an incorrect 404 with whoops enabled for those kind of exceptions. Such exceptions can not only be caused by a firstOrFail but also by middleware, global scopes or random abort() calls.

@dsevillamartin
Copy link
Member

If Whoops was kept for non-500 errors, which I agree with @luceos in that it would help debug, IMO it should still return the error code as the HTTP status.
Currently it only returns 500, which makes 404 errors look like server errors and can scare me a bit sometimes 😂

@franzliedke
Copy link
Contributor

If Whoops was kept for non-500 errors, which I agree with @luceos in that it would help debug, IMO it should still return the error code as the HTTP status.

That is a great suggestion and would alleviate most of my concerns.

@franzliedke
Copy link
Contributor

Now that #1648 is merged, what's left here is a rethink of how logging, exception handling and exception rendering fit together.

This also raises the question of how the new CSRF token mismatch handling fits in - generating the same status code from different exceptions is now possible, which means that we probably want to vary the returned pretty view based on the exception type, not the status code.

franzliedke added a commit to flarum/lang-english that referenced this issue Aug 14, 2019
...instead of status code. There are (or will be) multiple different
keys for similar errors with the same status code. In the future, we
will use the error's "type" (see flarum/framework#1843) to distinguish them.

Refs flarum/framework#1641.
franzliedke added a commit to flarum/lang-english that referenced this issue Aug 21, 2019
franzliedke added a commit that referenced this issue Aug 21, 2019
It has the same effect as the PermissionDeniedException, so let's
just use that.

Refs #1641.
luceos pushed a commit that referenced this issue Feb 4, 2020
...not based on status code.

To simplify this logic, we now use the same error "type" both when
routes are not found and specific models are not found. One exception is
ours, one is from Laravel, but for the purposes of error handling they
should be treated the same.

Fixes #1641.
luceos pushed a commit that referenced this issue Feb 4, 2020
luceos pushed a commit that referenced this issue Feb 4, 2020
It has the same effect as the PermissionDeniedException, so let's
just use that.

Refs #1641.
wzdiyb pushed a commit to wzdiyb/core that referenced this issue Feb 16, 2020
...not based on status code.

To simplify this logic, we now use the same error "type" both when
routes are not found and specific models are not found. One exception is
ours, one is from Laravel, but for the purposes of error handling they
should be treated the same.

Fixes flarum#1641.
wzdiyb pushed a commit to wzdiyb/core that referenced this issue Feb 16, 2020
wzdiyb pushed a commit to wzdiyb/core that referenced this issue Feb 16, 2020
It has the same effect as the PermissionDeniedException, so let's
just use that.

Refs flarum#1641.
askvortsov1 pushed a commit to flarum/lang-english that referenced this issue Mar 11, 2022
...instead of status code. There are (or will be) multiple different
keys for similar errors with the same status code. In the future, we
will use the error's "type" (see flarum/framework#1843) to distinguish them.

Refs flarum/framework#1641.
askvortsov1 pushed a commit to flarum/lang-english that referenced this issue Mar 11, 2022
askvortsov1 pushed a commit to flarum/lang-english that referenced this issue May 10, 2022
...instead of status code. There are (or will be) multiple different
keys for similar errors with the same status code. In the future, we
will use the error's "type" (see flarum/framework#1843) to distinguish them.

Refs flarum/framework#1641.
askvortsov1 pushed a commit to flarum/lang-english that referenced this issue May 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants