forked from mtusi2026/mtusi2026lab5
25 lines
822 B
Java
25 lines
822 B
Java
package ru.mtusi.messenger;
|
|
|
|
public class ApiException extends RuntimeException {
|
|
private final int status;
|
|
private final String code;
|
|
|
|
public ApiException(int status, String code, String message) {
|
|
super(message);
|
|
this.status = status;
|
|
this.code = code;
|
|
}
|
|
|
|
public int status() { return status; }
|
|
public String code() { return code; }
|
|
public static ApiException invalid(String message) {
|
|
return new ApiException(400, "invalid_request", message);
|
|
}
|
|
public static ApiException unauthorized() {
|
|
return new ApiException(401, "unauthorized", "Требуется действующая Bearer-сессия");
|
|
}
|
|
public static ApiException notFound() {
|
|
return new ApiException(404, "not_found", "Объект не найден");
|
|
}
|
|
}
|