Example usage for org.springframework.http HttpStatus is4xxClientError

List of usage examples for org.springframework.http HttpStatus is4xxClientError

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus is4xxClientError.

Prototype

public boolean is4xxClientError() 

Source Link

Document

Whether this status code is in the HTTP series org.springframework.http.HttpStatus.Series#CLIENT_ERROR .

Usage

From source file:cn.edu.zjnu.acm.judge.exception.GlobalExceptionHandler.java

@ExceptionHandler(MessageException.class)
public String messageExceptionHandler(HttpServletRequest request, HttpServletResponse response,
        MessageException ex) {/*from  w w  w  .  j  a  va  2  s  .c  o m*/
    String message = ex.getMessage();
    HttpStatus code = ex.getHttpStatus();
    try {
        message = messageSource.getMessage(message, null, localeResolver.resolveLocale(request));
    } catch (NoSuchMessageException ignore) {
    }
    request.setAttribute("message", message);
    if (code.is4xxClientError()) {
        response.setStatus(code.value());
    }
    return "message";
}