Support for custom status in ResponseStatusException

Closes gh-20336
This commit is contained in:
Rossen Stoyanchev
2020-07-09 15:06:33 +03:00
parent 4d7418841c
commit 37366e0c91
5 changed files with 68 additions and 29 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,8 +17,6 @@
package org.springframework.web.reactive.handler;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.http.HttpStatus;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.server.handler.ResponseStatusExceptionHandler;
@@ -39,13 +37,12 @@ import org.springframework.web.server.handler.ResponseStatusExceptionHandler;
public class WebFluxResponseStatusExceptionHandler extends ResponseStatusExceptionHandler {
@Override
@Nullable
protected HttpStatus determineStatus(Throwable ex) {
HttpStatus status = super.determineStatus(ex);
if (status == null) {
protected int determineRawStatusCode(Throwable ex) {
int status = super.determineRawStatusCode(ex);
if (status == -1) {
ResponseStatus ann = AnnotatedElementUtils.findMergedAnnotation(ex.getClass(), ResponseStatus.class);
if (ann != null) {
status = ann.code();
status = ann.code().value();
}
}
return status;