Joaquín Reñé
2025-10-07 146a0fb8b0e90f9196e569152f649baf60d6cc8f
securis/src/main/java/net/curisit/securis/services/exception/SeCurisServiceException.java
....@@ -1,51 +1,90 @@
1
+/*
2
+ * Copyright @ 2013 CurisTEC, S.A.S. All Rights Reserved.
3
+ */
14 package net.curisit.securis.services.exception;
25
36 import net.curisit.integrity.exception.CurisException;
47
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
+ */
522 public class SeCurisServiceException extends CurisException {
623
7
- private int errorCode = 0;
24
+ /** Numeric error code associated with this exception. */
25
+ private int errorCode = 0;
826
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
+ }
1337
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
+ }
1847
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
+ }
2258
23
- /**
24
- *
25
- */
26
- private static final long serialVersionUID = 1L;
59
+ private static final long serialVersionUID = 1L;
2760
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;
3675
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;
4281
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;
4887
49
- public static int INVALID_DATA = 1301;
50
- }
88
+ public static int INVALID_DATA = 1301;
89
+ }
5190 }