/** * Get HTTP response status associated with this exception as {@link HttpStatus}, if available and known. * @return Optional HTTP response status */ public Optional<HttpStatus> getStatus() { return HttpStatus.of(getStatusCode()); }
/** * Constructor with status code * @param statusCode HTTP status code */ public HttpStatusCodeException(int statusCode) { super(HttpStatus.of(statusCode).map(s -> s.getCode() + " - " + s.getDescription()) .orElse("HTTP status code: " + statusCode)); this.statusCode = statusCode; }
/** * Get the response status as {@link HttpStatus} * @return the response HttpStatus * @throws InvalidHttpMessageException If the status code of the message does not corresponds to any of the * {@link HttpStatus} values */ default HttpStatus getStatus() { return HttpStatus.of(getStatusCode()) .orElseThrow(() -> new InvalidHttpMessageException("Unknown status code: " + getStatusCode())); }