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