| .. | .. |
|---|
| 1 | +/* |
|---|
| 2 | + * Copyright @ 2013 CurisTEC, S.A.S. All Rights Reserved. |
|---|
| 3 | + */ |
|---|
| 1 | 4 | package net.curisit.securis.services.exception; |
|---|
| 2 | 5 | |
|---|
| 3 | 6 | import net.curisit.integrity.exception.CurisException; |
|---|
| 4 | 7 | |
|---|
| 8 | +/** |
|---|
| 9 | + * SeCurisServiceException |
|---|
| 10 | + * <p> |
|---|
| 11 | + * Checked exception for service-layer errors with an attached numeric error code. |
|---|
| 12 | + * Extends {@link CurisException} and is intended to be translated to HTTP responses |
|---|
| 13 | + * by upstream exception mappers/handlers. |
|---|
| 14 | + * |
|---|
| 15 | + * Usage: |
|---|
| 16 | + * - Prefer specific {@code ErrorCodes.*} when throwing. |
|---|
| 17 | + * - Use the single-arg constructor to default to UNEXPECTED_ERROR. |
|---|
| 18 | + * |
|---|
| 19 | + * @author JRA |
|---|
| 20 | + * Last reviewed by JRA on Oct 5, 2025. |
|---|
| 21 | + */ |
|---|
| 5 | 22 | public class SeCurisServiceException extends CurisException { |
|---|
| 6 | 23 | |
|---|
| 7 | | - private int errorCode = 0; |
|---|
| 24 | + /** Numeric error code associated with this exception. */ |
|---|
| 25 | + private int errorCode = 0; |
|---|
| 8 | 26 | |
|---|
| 9 | | - public SeCurisServiceException(int errorCode, String msg) { |
|---|
| 10 | | - super(msg); |
|---|
| 11 | | - this.errorCode = errorCode; |
|---|
| 12 | | - } |
|---|
| 27 | + /** |
|---|
| 28 | + * Constructor with explicit error code. |
|---|
| 29 | + * |
|---|
| 30 | + * @param errorCode See {@link ErrorCodes}. |
|---|
| 31 | + * @param msg Human-readable message (safe to expose). |
|---|
| 32 | + */ |
|---|
| 33 | + public SeCurisServiceException(int errorCode, String msg) { |
|---|
| 34 | + super(msg); |
|---|
| 35 | + this.errorCode = errorCode; |
|---|
| 36 | + } |
|---|
| 13 | 37 | |
|---|
| 14 | | - public SeCurisServiceException(String msg) { |
|---|
| 15 | | - super(msg); |
|---|
| 16 | | - this.errorCode = ErrorCodes.UNEXPECTED_ERROR; |
|---|
| 17 | | - } |
|---|
| 38 | + /** |
|---|
| 39 | + * Constructor defaulting to {@link ErrorCodes#UNEXPECTED_ERROR}. |
|---|
| 40 | + * |
|---|
| 41 | + * @param msg Human-readable message (safe to expose). |
|---|
| 42 | + */ |
|---|
| 43 | + public SeCurisServiceException(String msg) { |
|---|
| 44 | + super(msg); |
|---|
| 45 | + this.errorCode = ErrorCodes.UNEXPECTED_ERROR; |
|---|
| 46 | + } |
|---|
| 18 | 47 | |
|---|
| 19 | | - public int getStatus() { |
|---|
| 20 | | - return errorCode; |
|---|
| 21 | | - } |
|---|
| 48 | + /** |
|---|
| 49 | + * getStatus |
|---|
| 50 | + * <p> |
|---|
| 51 | + * Returns the stored numeric error code. |
|---|
| 52 | + * |
|---|
| 53 | + * @return integer error code. |
|---|
| 54 | + */ |
|---|
| 55 | + public int getStatus() { |
|---|
| 56 | + return errorCode; |
|---|
| 57 | + } |
|---|
| 22 | 58 | |
|---|
| 23 | | - /** |
|---|
| 24 | | - * |
|---|
| 25 | | - */ |
|---|
| 26 | | - private static final long serialVersionUID = 1L; |
|---|
| 59 | + private static final long serialVersionUID = 1L; |
|---|
| 27 | 60 | |
|---|
| 28 | | - public static class ErrorCodes { |
|---|
| 29 | | - public static int UNEXPECTED_ERROR = 1000; |
|---|
| 30 | | - public static int INVALID_CREDENTIALS = 1001; |
|---|
| 31 | | - public static int UNAUTHORIZED_ACCESS = 1002; |
|---|
| 32 | | - public static int NOT_FOUND = 1003; |
|---|
| 33 | | - public static int INVALID_FORMAT = 1004; |
|---|
| 34 | | - public static int WRONG_STATUS = 1005; |
|---|
| 35 | | - public static int UNNECESSARY_RENEW = 1006; |
|---|
| 61 | + /** |
|---|
| 62 | + * ErrorCodes |
|---|
| 63 | + * <p> |
|---|
| 64 | + * Canonical set of service-layer error codes. |
|---|
| 65 | + * Grouped by feature areas (1000 generic, 11xx license, 12xx request data, 13xx validation). |
|---|
| 66 | + */ |
|---|
| 67 | + public static class ErrorCodes { |
|---|
| 68 | + public static int UNEXPECTED_ERROR = 1000; |
|---|
| 69 | + public static int INVALID_CREDENTIALS = 1001; |
|---|
| 70 | + public static int UNAUTHORIZED_ACCESS = 1002; |
|---|
| 71 | + public static int NOT_FOUND = 1003; |
|---|
| 72 | + public static int INVALID_FORMAT = 1004; |
|---|
| 73 | + public static int WRONG_STATUS = 1005; |
|---|
| 74 | + public static int UNNECESSARY_RENEW = 1006; |
|---|
| 36 | 75 | |
|---|
| 37 | | - public static int INVALID_LICENSE_REQUEST_DATA = 1100; |
|---|
| 38 | | - public static int LICENSE_NOT_READY_FOR_RENEW = 1101; |
|---|
| 39 | | - public static int LICENSE_DATA_IS_NOT_VALID = 1102; |
|---|
| 40 | | - public static int LICENSE_IS_EXPIRED = 1103; |
|---|
| 41 | | - public static int LICENSE_PACK_IS_NOT_VALID = 1104; |
|---|
| 76 | + public static int INVALID_LICENSE_REQUEST_DATA = 1100; |
|---|
| 77 | + public static int LICENSE_NOT_READY_FOR_RENEW = 1101; |
|---|
| 78 | + public static int LICENSE_DATA_IS_NOT_VALID = 1102; |
|---|
| 79 | + public static int LICENSE_IS_EXPIRED = 1103; |
|---|
| 80 | + public static int LICENSE_PACK_IS_NOT_VALID = 1104; |
|---|
| 42 | 81 | |
|---|
| 43 | | - public static int INVALID_REQUEST_DATA = 1201; |
|---|
| 44 | | - public static int INVALID_REQUEST_DATA_FORMAT = 1202; |
|---|
| 45 | | - public static int BLOCKED_REQUEST_DATA = 1203; |
|---|
| 46 | | - public static int DUPLICATED_REQUEST_DATA = 1204; |
|---|
| 47 | | - public static int NO_AVAILABLE_LICENSES = 1205; |
|---|
| 82 | + public static int INVALID_REQUEST_DATA = 1201; |
|---|
| 83 | + public static int INVALID_REQUEST_DATA_FORMAT = 1202; |
|---|
| 84 | + public static int BLOCKED_REQUEST_DATA = 1203; |
|---|
| 85 | + public static int DUPLICATED_REQUEST_DATA = 1204; |
|---|
| 86 | + public static int NO_AVAILABLE_LICENSES = 1205; |
|---|
| 48 | 87 | |
|---|
| 49 | | - public static int INVALID_DATA = 1301; |
|---|
| 50 | | - } |
|---|
| 88 | + public static int INVALID_DATA = 1301; |
|---|
| 89 | + } |
|---|
| 51 | 90 | } |
|---|