Skip to content

Simplify creating RFC 7807 responses from functional endpoints  #29462

@rstoyanchev

Description

@rstoyanchev

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.

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions