Case Punching Feature Done
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
package lib.constants;
|
||||
|
||||
/** Canonical user-facing messages shared by Cygnus applications. */
|
||||
public enum ApplicationMessage {
|
||||
BAD_REQUEST(400, "HTTP-400", "Invalid request",
|
||||
"Cygnus could not process the submitted request.",
|
||||
"Review the supplied information and try again."),
|
||||
SESSION_REQUIRED(401, "AUTH-401", "Sign in required",
|
||||
"Your session is missing or has expired.",
|
||||
"Sign in again to continue securely."),
|
||||
ACCESS_DENIED(403, "AUTH-403", "Access denied",
|
||||
"You do not have permission to open this page.",
|
||||
"Contact your administrator if this feature should be available to you."),
|
||||
PAGE_NOT_FOUND(404, "HTTP-404", "Page not found",
|
||||
"The requested page could not be found.",
|
||||
"Check the address or return to the application dashboard."),
|
||||
METHOD_NOT_ALLOWED(405, "HTTP-405", "Action not allowed",
|
||||
"This page does not support the requested action.",
|
||||
"Return to the previous page and try an available action."),
|
||||
CONFLICT(409, "HTTP-409", "Request conflict",
|
||||
"The request conflicts with the current state of the data.",
|
||||
"Refresh the page and try again."),
|
||||
PAYLOAD_TOO_LARGE(413, "HTTP-413", "File is too large",
|
||||
"The submitted content exceeds the permitted size.",
|
||||
"Reduce the file size and try again."),
|
||||
TOO_MANY_REQUESTS(429, "HTTP-429", "Too many requests",
|
||||
"Cygnus has received too many requests in a short period.",
|
||||
"Wait briefly before trying again."),
|
||||
PAYLOAD_INVALID(400, "REQ-4001", "Invalid request details",
|
||||
"The encrypted request could not be verified.",
|
||||
"Refresh the page and submit the form again."),
|
||||
APPLICATION_VALIDATION_FAILED(422, "APP-4221", "Application validation failed",
|
||||
"One or more application fields contain invalid information.",
|
||||
"Correct the highlighted fields and submit the application again."),
|
||||
APPLICATION_ACCESS_DENIED(403, "APP-4031", "Application access denied",
|
||||
"The selected portfolio or application is not available to your account.",
|
||||
"Select an authorized portfolio or contact your administrator."),
|
||||
APPLICATION_SAVE_CONFLICT(409, "APP-4091", "Application save conflict",
|
||||
"This request was already processed or the application changed.",
|
||||
"Refresh the application before submitting it again."),
|
||||
APPLICATION_SAVED(200, "APP-2001", "Application saved",
|
||||
"The application details were saved successfully.", ""),
|
||||
APPLICATION_SAVE_FAILED(500, "APP-5001", "Application could not be saved",
|
||||
"Cygnus could not save the application details.",
|
||||
"Try again. If the issue continues, share the reference ID with support."),
|
||||
INTERNAL_SERVER_ERROR(500, "HTTP-500", "Something went wrong",
|
||||
"Cygnus could not complete your request.",
|
||||
"Try again. If the issue continues, share the reference ID with support."),
|
||||
BAD_GATEWAY(502, "HTTP-502", "Service response unavailable",
|
||||
"A required service returned an invalid response.",
|
||||
"Try again shortly. If the issue continues, contact support."),
|
||||
SERVICE_UNAVAILABLE(503, "HTTP-503", "Service temporarily unavailable",
|
||||
"A required Cygnus service is currently unavailable.",
|
||||
"Wait briefly and try again."),
|
||||
GATEWAY_TIMEOUT(504, "HTTP-504", "Service response timed out",
|
||||
"A required service took too long to respond.",
|
||||
"Try the request again shortly.");
|
||||
|
||||
private final int httpStatus;
|
||||
private final String code;
|
||||
private final String title;
|
||||
private final String message;
|
||||
private final String description;
|
||||
|
||||
ApplicationMessage(
|
||||
int httpStatus, String code, String title, String message, String description) {
|
||||
this.httpStatus = httpStatus;
|
||||
this.code = code;
|
||||
this.title = title;
|
||||
this.message = message;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public static ApplicationMessage fromHttpStatus(int status) {
|
||||
return switch (status) {
|
||||
case 400 -> BAD_REQUEST;
|
||||
case 401 -> SESSION_REQUIRED;
|
||||
case 403 -> ACCESS_DENIED;
|
||||
case 404 -> PAGE_NOT_FOUND;
|
||||
case 405 -> METHOD_NOT_ALLOWED;
|
||||
case 409 -> CONFLICT;
|
||||
case 413 -> PAYLOAD_TOO_LARGE;
|
||||
case 429 -> TOO_MANY_REQUESTS;
|
||||
case 502 -> BAD_GATEWAY;
|
||||
case 503 -> SERVICE_UNAVAILABLE;
|
||||
case 504 -> GATEWAY_TIMEOUT;
|
||||
default -> INTERNAL_SERVER_ERROR;
|
||||
};
|
||||
}
|
||||
|
||||
public int getHttpStatus() { return httpStatus; }
|
||||
public String getCode() { return code; }
|
||||
public String getTitle() { return title; }
|
||||
public String getMessage() { return message; }
|
||||
public String getDescription() { return description; }
|
||||
}
|
||||
Reference in New Issue
Block a user