Skip to content

Map OptimisticLockingFailureException to CONFLICT by default #27219

@quaff

Description

@quaff

Currently Spring Boot will return INTERNAL_SERVER_ERROR if OptimisticLockingFailureException thrown, It's better to use CONFLICT instead, to archive that I need customize an ExceptionHandler

@ControllerAdvice
@RequiredArgsConstructor
public class GlobalExceptionHandler {

	@ExceptionHandler(OptimisticLockingFailureException.class)
	public void handleConflict(HttpServletRequest request, HttpServletResponse response, Exception e)
			throws IOException {
		response.sendError(HttpStatus.CONFLICT.value());
	}

}

It would be great if Spring Boot handle it by default, or provide a way to map in properties, for example:

server.error.mapping:
   "org.springframework.dao.OptimisticLockingFailureException": 409

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions