Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public class ResponseStatusException
- Object
- Throwable
- Exception
- RuntimeException
- ResponseStatusException
Known subtypesValidationException
Thrown by a handler to answer a request with a status of its choosing.
A handler that returns a value has no other way to say “409, that e-mail is
taken”: its return type is the body of a success. That is every method of a
server interface generated from a shared @RestClient contract, and any
controller method that returns its own type and not a Response.
if (taken(email)) {
throw new ResponseStatusException(409, "That e-mail already has an account");
}
The reason is the body, as plain text, so it is what the caller reads: keep it free of anything the caller should not learn. A status below 500 is an answer and is neither logged nor recorded as a failed request; 500 and above is reported as any other failure of the handler is, and answered with the status given.
Unchecked, as Spring’s is, and for the same reason: it has to pass through
methods whose signatures were written without it. Thrown inside a
@Transactional method it rolls the transaction back, as every unchecked
exception does.
Constructors
public ResponseStatusException(int status) | Answers with the status alone and an empty body, as Spring’s new ResponseStatusException(HttpStatus.NOT_FOUND) does. |
public ResponseStatusException(int status, String reason) | |
public ResponseStatusException(int status, String reason, Throwable cause) |
Methods
public int getStatus() | The status to answer with. |
public String getReason() | What the caller is told. |
Inherited methods
Constructor details
ResponseStatusException
public ResponseStatusException(int status)new ResponseStatusException(HttpStatus.NOT_FOUND) does.Parameters
statusint- the status to answer with, 400 to 599
ResponseStatusException
public ResponseStatusException(int status, String reason)Parameters
statusint- the status to answer with, 400 to 599
reasonString- what to tell the caller; sent as the body
ResponseStatusException
public ResponseStatusException(int status, String reason, Throwable cause)Parameters
statusint- the status to answer with, 400 to 599
reasonString- what to tell the caller; sent as the body
causeThrowable- what led to it, for the log; never sent
Method details
getStatus
public int getStatus()getReason
public String getReason()