Я пытаюсь бросить Exception с HttpStatus, но я не могу - PullRequest
0 голосов
/ 29 января 2019

У меня есть абстрактный класс AbstractResourse с методом createHuman ()

@AllArgsConstructor
public abstract class AbstractResource {

........

    @PostMapping
    public humanDto createHuman() {
        return service.createHuman();
    }

.......

в классе AdminResource. Я переопределяю метод createHuman ():

@RestController
@RequestMapping(value = "/admin/human", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class AdminResource extends AbstractResource{

    @Override
    public humanDto createHuman(humanDto entity) {
        throw new NotImplementedException();
    }

, и у меня есть класс NotImplementedException:

 @ResponseStatus(value = HttpStatus.METHOD_NOT_ALLOWED, 
reason = "Method not allowed")
public class NotImplementedException extends RuntimeException {
    public NotImplementedException (String s) {
        super(s);
    }
    public NotImplementedException () {
    }
}

Когда я делаю POST-запрос, я хочу получить исключение с помощью HttpStatus.Но я получил этот ответ от Swagger

Code: 500
Error:Response body
{
  "error": {
    "type": "EXCEPTION",
    "code": "EXCEPTION",
    "message": "NotImplementedException: Method not allowed",
    "businessException": true
  },
  "status": "ERROR",
  "correct": false
}

Я использую эту статью Baeldung

Мне нужна ваша помощь.Спасибо.

...