test
Форк от lirfrnk/test
1package com.bittercode.constant;
2
3import java.util.Arrays;
4import java.util.Optional;
5
6public enum ResponseCode {
7
8SUCCESS(200, "OK"),
9FAILURE(422, "Unprocessible Entity, Failed to Process"),
10PAGE_NOT_FOUND(404, "The Page You are Searching For is Not available"),
11ACCESS_DENIED(403, "Please Login First to continue"),
12BAD_REQUEST(400, "Bad Request, Please Try Again"),
13INTERNAL_SERVER_ERROR(500, "Internal Server Error, Try Again!!"),
14DATABASE_CONNECTION_FAILURE(406,
15"Unable to Connect to DB, Please Check your db credentials in application.properties"),
16METHOD_NOT_ALLOWED(405, "Requested HTTP method is not supported by this URL"),
17
18;
19
20private final String message;
21private final int code;
22
23ResponseCode(int code, String message) {
24this.message = message;
25this.code = code;
26}
27
28public String getMessage() {
29return message;
30}
31
32public int getCode() {
33return code;
34}
35
36// Reverse lookup methods
37public static Optional<ResponseCode> getMessageByStatusCode(int statusCode) {
38return Arrays.stream(ResponseCode.values())
39.filter(error -> error.getCode() == statusCode)
40.findFirst();
41}
42}
43