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

Simplify creating RFC 7807 responses from functional endpoints #29462

Closed
rstoyanchev opened this issue Nov 10, 2022 · 0 comments
Closed

Simplify creating RFC 7807 responses from functional endpoints #29462

rstoyanchev opened this issue Nov 10, 2022 · 0 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@rstoyanchev
Copy link
Contributor

rstoyanchev commented Nov 10, 2022

This is currently possible, but could be better:

RouterFunctions.route()
	.GET("/path", request -> {
		throw new IllegalArgumentException("...");
	})
	.onError(IllegalArgumentException.class, (ex, serverRequest) -> {
		ErrorResponse errorResponse = ErrorResponse.createFor(
				(Exception) ex, HttpStatus.BAD_REQUEST, null, "Invalid input", null, null);
		return ServerResponse.status(errorResponse.getStatusCode())
				.body(errorResponse.getBody());
	})
	.build()

We could add a ServerResponse#from(ErrorResponse) shortcut, and also provide a builder for ErrorResponse.

@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement labels Nov 10, 2022
@rstoyanchev rstoyanchev added this to the 6.0.0 milestone Nov 10, 2022
@rstoyanchev rstoyanchev self-assigned this Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant