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

Added an WebExceptionHandler #1178

Merged
merged 1 commit into from
Oct 15, 2020
Merged

Added an WebExceptionHandler #1178

merged 1 commit into from
Oct 15, 2020

Conversation

pc9795
Copy link
Contributor

@pc9795 pc9795 commented Oct 13, 2020

Description

All the errors which are not handled by @ExceptionHandler (ex- 404 by the Netty) are handled by DefaultErrorWebExceptionHandler which is autoconfigured by Spring boot.

The behaviour of this particular handler is to render an HTML for browsers and JSON for machines (ex- Postman):
https://github.com/spring-projects/spring-boot/blob/bd27756efcad283cf5b6bf790e54ce2a4192c0c7/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandler.java#L109

You can see the below screen shots:
image
image

But for APIs, we can create a custom handler to always render JSON, especially in our expected format.
Screenshot with this handler:
image

Fixes #804

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Manually

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented on my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

import static org.springframework.web.reactive.function.server.RouterFunctions.route;

@Component
@Order(-2)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This handler is ordered by @Order(-2) as the ordering of default handler is -1 so we want this to handle everything.

ServerProperties serverProperties, ApplicationContext applicationContext,
ObjectProvider<ViewResolver> viewResolvers,
ServerCodecConfigurer serverCodecConfigurer) {
super(errorAttributes, resourceProperties, serverProperties.getError(), applicationContext);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To check more about how it is configured look configuration of DefaultErrorWebExceptionHandler in ErrorWebFluxAutoConfiguration

@mohanarpit mohanarpit merged commit 7a1a2f5 into appsmithorg:release Oct 15, 2020
@mohanarpit
Copy link
Member

@pc9795 Thank you so much for this PR! It has been merged 🎉

@mohanarpit
Copy link
Member

@all-contributors Please add @pc9795 for their excellent contributions to improve Appsmith's code.

@allcontributors
Copy link
Contributor

@mohanarpit

I've put up a pull request to add @pc9795! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Login POST URL throws "Whitelabel Error Page"
2 participants