@carecard/common-util 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/lib/appErrorHandlers.js +105 -72
  2. package/package.json +1 -1
  3. package/coverage/clover.xml +0 -90
  4. package/coverage/coverage-final.json +0 -5
  5. package/coverage/lcov-report/appErrorHandlers.ts.html +0 -802
  6. package/coverage/lcov-report/base.css +0 -224
  7. package/coverage/lcov-report/block-navigation.js +0 -87
  8. package/coverage/lcov-report/favicon.png +0 -0
  9. package/coverage/lcov-report/index.html +0 -161
  10. package/coverage/lcov-report/index.ts.html +0 -94
  11. package/coverage/lcov-report/prettify.css +0 -1
  12. package/coverage/lcov-report/prettify.js +0 -2
  13. package/coverage/lcov-report/responseStatus.ts.html +0 -301
  14. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  15. package/coverage/lcov-report/sorter.js +0 -210
  16. package/coverage/lcov-report/utilityFunctions.ts.html +0 -187
  17. package/coverage/lcov.info +0 -194
  18. package/dist/cjs/appErrorHandlers.cjs +0 -179
  19. package/dist/cjs/appErrorHandlers.d.ts +0 -128
  20. package/dist/cjs/index.cjs +0 -19
  21. package/dist/cjs/index.d.ts +0 -3
  22. package/dist/cjs/responseStatus.cjs +0 -71
  23. package/dist/cjs/responseStatus.d.ts +0 -65
  24. package/dist/cjs/utilityFunctions.cjs +0 -30
  25. package/dist/cjs/utilityFunctions.d.ts +0 -9
  26. package/dist/esm/appErrorHandlers.d.ts +0 -128
  27. package/dist/esm/appErrorHandlers.js +0 -156
  28. package/dist/esm/index.d.ts +0 -3
  29. package/dist/esm/index.js +0 -3
  30. package/dist/esm/responseStatus.d.ts +0 -65
  31. package/dist/esm/responseStatus.js +0 -66
  32. package/dist/esm/utilityFunctions.d.ts +0 -9
  33. package/dist/esm/utilityFunctions.js +0 -27
@@ -1,187 +0,0 @@
1
-
2
- <!doctype html>
3
- <html lang="en">
4
-
5
- <head>
6
- <title>Code coverage report for utilityFunctions.ts</title>
7
- <meta charset="utf-8" />
8
- <link rel="stylesheet" href="prettify.css" />
9
- <link rel="stylesheet" href="base.css" />
10
- <link rel="shortcut icon" type="image/x-icon" href="favicon.png" />
11
- <meta name="viewport" content="width=device-width, initial-scale=1" />
12
- <style type='text/css'>
13
- .coverage-summary .sorter {
14
- background-image: url(sort-arrow-sprite.png);
15
- }
16
- </style>
17
- </head>
18
-
19
- <body>
20
- <div class='wrapper'>
21
- <div class='pad1'>
22
- <h1><a href="index.html">All files</a> utilityFunctions.ts</h1>
23
- <div class='clearfix'>
24
-
25
- <div class='fl pad1y space-right2'>
26
- <span class="strong">88.88% </span>
27
- <span class="quiet">Statements</span>
28
- <span class='fraction'>8/9</span>
29
- </div>
30
-
31
-
32
- <div class='fl pad1y space-right2'>
33
- <span class="strong">50% </span>
34
- <span class="quiet">Branches</span>
35
- <span class='fraction'>2/4</span>
36
- </div>
37
-
38
-
39
- <div class='fl pad1y space-right2'>
40
- <span class="strong">100% </span>
41
- <span class="quiet">Functions</span>
42
- <span class='fraction'>1/1</span>
43
- </div>
44
-
45
-
46
- <div class='fl pad1y space-right2'>
47
- <span class="strong">88.88% </span>
48
- <span class="quiet">Lines</span>
49
- <span class='fraction'>8/9</span>
50
- </div>
51
-
52
-
53
- </div>
54
- <p class="quiet">
55
- Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
56
- </p>
57
- <template id="filterTemplate">
58
- <div class="quiet">
59
- Filter:
60
- <input type="search" id="fileSearch">
61
- </div>
62
- </template>
63
- </div>
64
- <div class='status-line high'></div>
65
- <pre><table class="coverage">
66
- <tr><td class="line-count quiet"><a name='L1'></a><a href='#L1'>1</a>
67
- <a name='L2'></a><a href='#L2'>2</a>
68
- <a name='L3'></a><a href='#L3'>3</a>
69
- <a name='L4'></a><a href='#L4'>4</a>
70
- <a name='L5'></a><a href='#L5'>5</a>
71
- <a name='L6'></a><a href='#L6'>6</a>
72
- <a name='L7'></a><a href='#L7'>7</a>
73
- <a name='L8'></a><a href='#L8'>8</a>
74
- <a name='L9'></a><a href='#L9'>9</a>
75
- <a name='L10'></a><a href='#L10'>10</a>
76
- <a name='L11'></a><a href='#L11'>11</a>
77
- <a name='L12'></a><a href='#L12'>12</a>
78
- <a name='L13'></a><a href='#L13'>13</a>
79
- <a name='L14'></a><a href='#L14'>14</a>
80
- <a name='L15'></a><a href='#L15'>15</a>
81
- <a name='L16'></a><a href='#L16'>16</a>
82
- <a name='L17'></a><a href='#L17'>17</a>
83
- <a name='L18'></a><a href='#L18'>18</a>
84
- <a name='L19'></a><a href='#L19'>19</a>
85
- <a name='L20'></a><a href='#L20'>20</a>
86
- <a name='L21'></a><a href='#L21'>21</a>
87
- <a name='L22'></a><a href='#L22'>22</a>
88
- <a name='L23'></a><a href='#L23'>23</a>
89
- <a name='L24'></a><a href='#L24'>24</a>
90
- <a name='L25'></a><a href='#L25'>25</a>
91
- <a name='L26'></a><a href='#L26'>26</a>
92
- <a name='L27'></a><a href='#L27'>27</a>
93
- <a name='L28'></a><a href='#L28'>28</a>
94
- <a name='L29'></a><a href='#L29'>29</a>
95
- <a name='L30'></a><a href='#L30'>30</a>
96
- <a name='L31'></a><a href='#L31'>31</a>
97
- <a name='L32'></a><a href='#L32'>32</a>
98
- <a name='L33'></a><a href='#L33'>33</a>
99
- <a name='L34'></a><a href='#L34'>34</a>
100
- <a name='L35'></a><a href='#L35'>35</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
101
- <span class="cline-any cline-neutral">&nbsp;</span>
102
- <span class="cline-any cline-neutral">&nbsp;</span>
103
- <span class="cline-any cline-neutral">&nbsp;</span>
104
- <span class="cline-any cline-neutral">&nbsp;</span>
105
- <span class="cline-any cline-neutral">&nbsp;</span>
106
- <span class="cline-any cline-neutral">&nbsp;</span>
107
- <span class="cline-any cline-neutral">&nbsp;</span>
108
- <span class="cline-any cline-neutral">&nbsp;</span>
109
- <span class="cline-any cline-neutral">&nbsp;</span>
110
- <span class="cline-any cline-yes">3x</span>
111
- <span class="cline-any cline-neutral">&nbsp;</span>
112
- <span class="cline-any cline-neutral">&nbsp;</span>
113
- <span class="cline-any cline-neutral">&nbsp;</span>
114
- <span class="cline-any cline-neutral">&nbsp;</span>
115
- <span class="cline-any cline-yes">1x</span>
116
- <span class="cline-any cline-neutral">&nbsp;</span>
117
- <span class="cline-any cline-neutral">&nbsp;</span>
118
- <span class="cline-any cline-yes">1x</span>
119
- <span class="cline-any cline-no">&nbsp;</span>
120
- <span class="cline-any cline-neutral">&nbsp;</span>
121
- <span class="cline-any cline-neutral">&nbsp;</span>
122
- <span class="cline-any cline-neutral">&nbsp;</span>
123
- <span class="cline-any cline-yes">1x</span>
124
- <span class="cline-any cline-yes">2x</span>
125
- <span class="cline-any cline-neutral">&nbsp;</span>
126
- <span class="cline-any cline-yes">2x</span>
127
- <span class="cline-any cline-neutral">&nbsp;</span>
128
- <span class="cline-any cline-yes">2x</span>
129
- <span class="cline-any cline-neutral">&nbsp;</span>
130
- <span class="cline-any cline-neutral">&nbsp;</span>
131
- <span class="cline-any cline-neutral">&nbsp;</span>
132
- <span class="cline-any cline-yes">1x</span>
133
- <span class="cline-any cline-neutral">&nbsp;</span>
134
- <span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">// src/utilityFunctions.ts
135
- &nbsp;
136
- /**
137
- * Create a new object containing only the properties listed in `arrayOfProperties`.
138
- * Keeps the original behavior: only copies properties whose values are truthy.
139
- *
140
- * Example:
141
- * extractObjectWithProperties({ a: 1, b: 0, c: 'x' }, ['a', 'b', 'c'])
142
- * -&gt; { a: 1, c: 'x' } // 'b' is omitted because 0 is falsy
143
- */
144
- export function extractObjectWithProperties&lt;T extends Record&lt;string, unknown&gt;, K extends keyof T&gt;(
145
- obj: T | null | undefined,
146
- arrayOfProperties: ReadonlyArray&lt;K&gt;,
147
- ): Partial&lt;Pick&lt;T, K&gt;&gt; {
148
- // Initialize with the correct type to avoid "element implicitly has an 'any' type"
149
- const returnObj: Partial&lt;Pick&lt;T, K&gt;&gt; = {};
150
- &nbsp;
151
- // If obj is null/undefined, return an empty object
152
- <span class="missing-if-branch" title="if path not taken" >I</span>if (!obj) {
153
- <span class="cstat-no" title="statement not covered" > return returnObj;</span>
154
- }
155
- &nbsp;
156
- // Iterate using `for...of` to avoid lib/target issues with Array.prototype.find for older configs
157
- for (const nameOfProperty of arrayOfProperties) {
158
- const value = obj[nameOfProperty];
159
- // Preserve original "truthy" filter: only copy if value is truthy
160
- <span class="missing-if-branch" title="else path not taken" >E</span>if (value) {
161
- // Assign with proper typing
162
- returnObj[nameOfProperty] = value as T[K];
163
- }
164
- }
165
- &nbsp;
166
- return returnObj;
167
- }
168
- &nbsp;</pre></td></tr></table></pre>
169
-
170
- <div class='push'></div><!-- for sticky footer -->
171
- </div><!-- /wrapper -->
172
- <div class='footer quiet pad2 space-top1 center small'>
173
- Code coverage generated by
174
- <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
175
- at 2025-12-24T01:50:18.316Z
176
- </div>
177
- <script src="prettify.js"></script>
178
- <script>
179
- window.onload = function () {
180
- prettyPrint();
181
- };
182
- </script>
183
- <script src="sorter.js"></script>
184
- <script src="block-navigation.js"></script>
185
- </body>
186
- </html>
187
-
@@ -1,194 +0,0 @@
1
- TN:
2
- SF:src/appErrorHandlers.ts
3
- FN:35,(anonymous_0)
4
- FN:140,throwAppError
5
- FN:149,(anonymous_2)
6
- FN:152,(anonymous_3)
7
- FN:155,(anonymous_4)
8
- FN:157,(anonymous_5)
9
- FN:160,(anonymous_6)
10
- FN:163,(anonymous_7)
11
- FN:166,(anonymous_8)
12
- FN:168,(anonymous_9)
13
- FN:171,(anonymous_10)
14
- FN:173,(anonymous_11)
15
- FN:176,(anonymous_12)
16
- FN:179,(anonymous_13)
17
- FN:182,(anonymous_14)
18
- FN:184,(anonymous_15)
19
- FN:187,(anonymous_16)
20
- FN:190,(anonymous_17)
21
- FN:197,notFound404
22
- FN:207,appErrorHandler
23
- FNF:20
24
- FNH:19
25
- FNDA:16,(anonymous_0)
26
- FNDA:16,throwAppError
27
- FNDA:1,(anonymous_2)
28
- FNDA:1,(anonymous_3)
29
- FNDA:1,(anonymous_4)
30
- FNDA:1,(anonymous_5)
31
- FNDA:1,(anonymous_6)
32
- FNDA:1,(anonymous_7)
33
- FNDA:1,(anonymous_8)
34
- FNDA:1,(anonymous_9)
35
- FNDA:1,(anonymous_10)
36
- FNDA:1,(anonymous_11)
37
- FNDA:1,(anonymous_12)
38
- FNDA:1,(anonymous_13)
39
- FNDA:1,(anonymous_14)
40
- FNDA:1,(anonymous_15)
41
- FNDA:1,(anonymous_16)
42
- FNDA:1,(anonymous_17)
43
- FNDA:0,notFound404
44
- FNDA:16,appErrorHandler
45
- DA:30,3
46
- DA:36,16
47
- DA:37,16
48
- DA:38,16
49
- DA:39,16
50
- DA:40,16
51
- DA:48,3
52
- DA:140,3
53
- DA:141,16
54
- DA:142,16
55
- DA:149,3
56
- DA:150,1
57
- DA:152,3
58
- DA:153,1
59
- DA:155,3
60
- DA:157,3
61
- DA:158,1
62
- DA:160,3
63
- DA:161,1
64
- DA:163,3
65
- DA:164,1
66
- DA:166,3
67
- DA:168,3
68
- DA:169,1
69
- DA:171,3
70
- DA:173,3
71
- DA:174,1
72
- DA:176,3
73
- DA:177,1
74
- DA:179,3
75
- DA:180,1
76
- DA:182,3
77
- DA:184,3
78
- DA:185,1
79
- DA:187,3
80
- DA:188,1
81
- DA:190,3
82
- DA:191,1
83
- DA:197,3
84
- DA:198,0
85
- DA:207,3
86
- DA:219,16
87
- DA:221,16
88
- DA:222,16
89
- DA:223,136
90
- DA:224,136
91
- DA:225,16
92
- DA:226,16
93
- DA:230,16
94
- DA:232,16
95
- LF:50
96
- LH:49
97
- BRDA:35,0,0,0
98
- BRDA:39,1,0,16
99
- BRDA:39,1,1,16
100
- BRDA:40,2,0,16
101
- BRDA:40,2,1,16
102
- BRDA:140,3,0,0
103
- BRDA:149,4,0,1
104
- BRDA:152,5,0,1
105
- BRDA:155,6,0,1
106
- BRDA:157,7,0,1
107
- BRDA:160,8,0,1
108
- BRDA:163,9,0,1
109
- BRDA:166,10,0,1
110
- BRDA:168,11,0,1
111
- BRDA:171,12,0,1
112
- BRDA:173,13,0,1
113
- BRDA:176,14,0,1
114
- BRDA:179,15,0,1
115
- BRDA:182,16,0,1
116
- BRDA:184,17,0,1
117
- BRDA:187,18,0,1
118
- BRDA:190,19,0,1
119
- BRDA:224,20,0,16
120
- BRDA:224,20,1,120
121
- BRDA:230,21,0,16
122
- BRDA:230,21,1,0
123
- BRDA:234,22,0,16
124
- BRDA:234,22,1,0
125
- BRDA:234,22,2,0
126
- BRDA:235,23,0,16
127
- BRDA:235,23,1,16
128
- BRDA:235,23,2,0
129
- BRDA:236,24,0,16
130
- BRDA:236,24,1,16
131
- BRF:34
132
- BRH:28
133
- end_of_record
134
- TN:
135
- SF:src/index.ts
136
- FNF:0
137
- FNH:0
138
- DA:1,3
139
- DA:2,3
140
- DA:3,3
141
- LF:3
142
- LH:3
143
- BRF:0
144
- BRH:0
145
- end_of_record
146
- TN:
147
- SF:src/responseStatus.ts
148
- FN:29,setOk200
149
- FN:55,setCreated201
150
- FN:69,setBadRequest400ClientError
151
- FNF:3
152
- FNH:3
153
- FNDA:1,setOk200
154
- FNDA:1,setCreated201
155
- FNDA:1,setBadRequest400ClientError
156
- DA:29,3
157
- DA:33,1
158
- DA:34,1
159
- DA:36,1
160
- DA:55,3
161
- DA:56,1
162
- DA:57,1
163
- DA:69,3
164
- DA:70,1
165
- DA:71,1
166
- LF:10
167
- LH:10
168
- BRF:0
169
- BRH:0
170
- end_of_record
171
- TN:
172
- SF:src/utilityFunctions.ts
173
- FN:11,extractObjectWithProperties
174
- FNF:1
175
- FNH:1
176
- FNDA:1,extractObjectWithProperties
177
- DA:11,3
178
- DA:16,1
179
- DA:19,1
180
- DA:20,0
181
- DA:24,1
182
- DA:25,2
183
- DA:27,2
184
- DA:29,2
185
- DA:33,1
186
- LF:9
187
- LH:8
188
- BRDA:19,0,0,0
189
- BRDA:19,0,1,1
190
- BRDA:27,1,0,2
191
- BRDA:27,1,1,0
192
- BRF:4
193
- BRH:2
194
- end_of_record
@@ -1,179 +0,0 @@
1
- "use strict";
2
- /* appErrors.ts */
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.throwInvalidTimeValueError = exports.throwFileTooLargeError = exports.throwInputNotUuidError = exports.throwBadInputError = exports.throwNotAuthorizedError = exports.throwFileFormatNotSupportedError = exports.throwBadVisitorTokenError = exports.throwUsedTokenError = exports.throwTransactionFailedError = exports.throwUpdateFailedError = exports.throwLoginRequiredError = exports.throwRecordNotSavedError = exports.throwRecordNotFoundError = exports.throwRecordExistError = exports.throwWrongCredentialsError = exports.throwValidationFailureError = exports.ERROR_TYPES = exports.AppError = void 0;
5
- exports.throwAppError = throwAppError;
6
- exports.notFound404 = notFound404;
7
- exports.appErrorHandler = appErrorHandler;
8
- /* --------------------------------------------------
9
- * Base Error Class
10
- * -------------------------------------------------- */
11
- class AppError extends Error {
12
- constructor(message, code, params = {}) {
13
- super(message);
14
- this.name = 'AppError';
15
- this.code = code;
16
- this.userMessage = params.userMessage ?? null;
17
- this.details = params.details ?? null;
18
- }
19
- }
20
- exports.AppError = AppError;
21
- /* --------------------------------------------------
22
- * Error Registry (single source of truth)
23
- * -------------------------------------------------- */
24
- exports.ERROR_TYPES = {
25
- VALIDATION_FAILURE: {
26
- message: 'Validation_Failure',
27
- code: 'VALIDATION_FAILURE',
28
- status: 401,
29
- },
30
- WRONG_CREDENTIALS: {
31
- message: 'Wrong_Credentials',
32
- code: 'WRONG_CREDENTIALS',
33
- status: 401,
34
- },
35
- USED_TOKEN: {
36
- message: 'Used_Token',
37
- code: 'USED_TOKEN',
38
- status: 401,
39
- },
40
- BAD_VISITOR_TOKEN: {
41
- message: 'Bad_Visitor_Token',
42
- code: 'BAD_VISITOR_TOKEN',
43
- status: 401,
44
- },
45
- LOGIN_REQUIRED: {
46
- message: 'Login_Required',
47
- code: 'LOGIN_REQUIRED',
48
- status: 401,
49
- },
50
- NOT_AUTHORIZED: {
51
- message: 'Not_Authorized',
52
- code: 'NOT_AUTHORIZED',
53
- status: 401,
54
- },
55
- BAD_INPUT: {
56
- message: 'Bad_Input',
57
- code: 'BAD_INPUT',
58
- status: 400,
59
- },
60
- INPUT_NOT_UUID: {
61
- message: 'Input_Not_Uuid',
62
- code: 'INPUT_NOT_UUID',
63
- status: 400,
64
- },
65
- RECORD_NOT_SAVED: {
66
- message: 'Record_NotSaved',
67
- code: 'RECORD_NOT_SAVED',
68
- status: 400,
69
- },
70
- UPDATE_FAILED: {
71
- message: 'Update_Failed',
72
- code: 'UPDATE_FAILED',
73
- status: 400,
74
- },
75
- TRANSACTION_FAILED: {
76
- message: 'Transaction_Failed',
77
- code: 'TRANSACTION_FAILED',
78
- status: 400,
79
- },
80
- RECORD_EXIST: {
81
- message: 'Record_Exist',
82
- code: 'RECORD_EXIST',
83
- status: 409,
84
- },
85
- RECORD_NOT_FOUND: {
86
- message: 'Record_NotFound',
87
- code: 'RECORD_NOT_FOUND',
88
- status: 404,
89
- },
90
- FILE_FORMAT_NOT_SUPPORTED: {
91
- message: 'File_Format_Not_Supported',
92
- code: 'FILE_FORMAT_NOT_SUPPORTED',
93
- status: 415,
94
- },
95
- FILE_TOO_LARGE: {
96
- message: 'File too large',
97
- code: 'FILE_TOO_LARGE',
98
- status: 413,
99
- },
100
- INVALID_TIME_VALUE: {
101
- message: 'Invalid time value',
102
- code: 'INVALID_TIME_VALUE',
103
- status: 403,
104
- },
105
- };
106
- /* --------------------------------------------------
107
- * Generic throw helper
108
- * -------------------------------------------------- */
109
- function throwAppError(type, params = {}) {
110
- const { message, code } = exports.ERROR_TYPES[type];
111
- throw new AppError(message, code, params);
112
- }
113
- /* --------------------------------------------------
114
- * Backward-compatible helpers (optional)
115
- * -------------------------------------------------- */
116
- const throwValidationFailureError = (p = {}) => throwAppError('VALIDATION_FAILURE', p);
117
- exports.throwValidationFailureError = throwValidationFailureError;
118
- const throwWrongCredentialsError = (p = {}) => throwAppError('WRONG_CREDENTIALS', p);
119
- exports.throwWrongCredentialsError = throwWrongCredentialsError;
120
- const throwRecordExistError = (p = {}) => throwAppError('RECORD_EXIST', p);
121
- exports.throwRecordExistError = throwRecordExistError;
122
- const throwRecordNotFoundError = (p = {}) => throwAppError('RECORD_NOT_FOUND', p);
123
- exports.throwRecordNotFoundError = throwRecordNotFoundError;
124
- const throwRecordNotSavedError = (p = {}) => throwAppError('RECORD_NOT_SAVED', p);
125
- exports.throwRecordNotSavedError = throwRecordNotSavedError;
126
- const throwLoginRequiredError = (p = {}) => throwAppError('LOGIN_REQUIRED', p);
127
- exports.throwLoginRequiredError = throwLoginRequiredError;
128
- const throwUpdateFailedError = (p = {}) => throwAppError('UPDATE_FAILED', p);
129
- exports.throwUpdateFailedError = throwUpdateFailedError;
130
- const throwTransactionFailedError = (p = {}) => throwAppError('TRANSACTION_FAILED', p);
131
- exports.throwTransactionFailedError = throwTransactionFailedError;
132
- const throwUsedTokenError = (p = {}) => throwAppError('USED_TOKEN', p);
133
- exports.throwUsedTokenError = throwUsedTokenError;
134
- const throwBadVisitorTokenError = (p = {}) => throwAppError('BAD_VISITOR_TOKEN', p);
135
- exports.throwBadVisitorTokenError = throwBadVisitorTokenError;
136
- const throwFileFormatNotSupportedError = (p = {}) => throwAppError('FILE_FORMAT_NOT_SUPPORTED', p);
137
- exports.throwFileFormatNotSupportedError = throwFileFormatNotSupportedError;
138
- const throwNotAuthorizedError = (p = {}) => throwAppError('NOT_AUTHORIZED', p);
139
- exports.throwNotAuthorizedError = throwNotAuthorizedError;
140
- const throwBadInputError = (p = {}) => throwAppError('BAD_INPUT', p);
141
- exports.throwBadInputError = throwBadInputError;
142
- const throwInputNotUuidError = (p = {}) => throwAppError('INPUT_NOT_UUID', p);
143
- exports.throwInputNotUuidError = throwInputNotUuidError;
144
- const throwFileTooLargeError = (p = {}) => throwAppError('FILE_TOO_LARGE', p);
145
- exports.throwFileTooLargeError = throwFileTooLargeError;
146
- const throwInvalidTimeValueError = (p = {}) => throwAppError('INVALID_TIME_VALUE', p);
147
- exports.throwInvalidTimeValueError = throwInvalidTimeValueError;
148
- /* --------------------------------------------------
149
- * Express middleware
150
- * -------------------------------------------------- */
151
- function notFound404(req, res, _next) {
152
- res.status(404).send({
153
- error: {
154
- code: 'NOT_FOUND',
155
- message: 'Not found',
156
- details: null,
157
- },
158
- });
159
- }
160
- function appErrorHandler(err, _req, res, _next) {
161
- // Iteration without `.find` or `Object.values` for maximum compatibility
162
- let errorType = undefined;
163
- const keys = Object.keys(exports.ERROR_TYPES);
164
- for (const key of keys) {
165
- const candidate = exports.ERROR_TYPES[key];
166
- if (candidate.message === err?.message) {
167
- errorType = candidate;
168
- break;
169
- }
170
- }
171
- const status = errorType?.status ?? 500;
172
- res.status(status).send({
173
- error: {
174
- code: err?.code ?? errorType?.code ?? null,
175
- message: err?.userMessage ?? errorType?.message ?? null,
176
- details: err?.details ?? null,
177
- },
178
- });
179
- }
@@ -1,128 +0,0 @@
1
- /**
2
- * Application-level error handling utilities.
3
- * Use throwXxxError functions in services/controllers.
4
- * Use appErrorHandler + notFound404 in app.js.
5
- */
6
- import type { Request, Response, NextFunction } from 'express';
7
- export interface AppErrorParams {
8
- userMessage?: string | null;
9
- details?: unknown;
10
- }
11
- export type ErrorInfo = {
12
- message: string;
13
- code: string;
14
- status: number;
15
- };
16
- export declare class AppError extends Error {
17
- readonly code: string;
18
- readonly userMessage: string | null;
19
- readonly details: unknown;
20
- constructor(message: string, code: string, params?: AppErrorParams);
21
- }
22
- export declare const ERROR_TYPES: {
23
- readonly VALIDATION_FAILURE: {
24
- readonly message: "Validation_Failure";
25
- readonly code: "VALIDATION_FAILURE";
26
- readonly status: 401;
27
- };
28
- readonly WRONG_CREDENTIALS: {
29
- readonly message: "Wrong_Credentials";
30
- readonly code: "WRONG_CREDENTIALS";
31
- readonly status: 401;
32
- };
33
- readonly USED_TOKEN: {
34
- readonly message: "Used_Token";
35
- readonly code: "USED_TOKEN";
36
- readonly status: 401;
37
- };
38
- readonly BAD_VISITOR_TOKEN: {
39
- readonly message: "Bad_Visitor_Token";
40
- readonly code: "BAD_VISITOR_TOKEN";
41
- readonly status: 401;
42
- };
43
- readonly LOGIN_REQUIRED: {
44
- readonly message: "Login_Required";
45
- readonly code: "LOGIN_REQUIRED";
46
- readonly status: 401;
47
- };
48
- readonly NOT_AUTHORIZED: {
49
- readonly message: "Not_Authorized";
50
- readonly code: "NOT_AUTHORIZED";
51
- readonly status: 401;
52
- };
53
- readonly BAD_INPUT: {
54
- readonly message: "Bad_Input";
55
- readonly code: "BAD_INPUT";
56
- readonly status: 400;
57
- };
58
- readonly INPUT_NOT_UUID: {
59
- readonly message: "Input_Not_Uuid";
60
- readonly code: "INPUT_NOT_UUID";
61
- readonly status: 400;
62
- };
63
- readonly RECORD_NOT_SAVED: {
64
- readonly message: "Record_NotSaved";
65
- readonly code: "RECORD_NOT_SAVED";
66
- readonly status: 400;
67
- };
68
- readonly UPDATE_FAILED: {
69
- readonly message: "Update_Failed";
70
- readonly code: "UPDATE_FAILED";
71
- readonly status: 400;
72
- };
73
- readonly TRANSACTION_FAILED: {
74
- readonly message: "Transaction_Failed";
75
- readonly code: "TRANSACTION_FAILED";
76
- readonly status: 400;
77
- };
78
- readonly RECORD_EXIST: {
79
- readonly message: "Record_Exist";
80
- readonly code: "RECORD_EXIST";
81
- readonly status: 409;
82
- };
83
- readonly RECORD_NOT_FOUND: {
84
- readonly message: "Record_NotFound";
85
- readonly code: "RECORD_NOT_FOUND";
86
- readonly status: 404;
87
- };
88
- readonly FILE_FORMAT_NOT_SUPPORTED: {
89
- readonly message: "File_Format_Not_Supported";
90
- readonly code: "FILE_FORMAT_NOT_SUPPORTED";
91
- readonly status: 415;
92
- };
93
- readonly FILE_TOO_LARGE: {
94
- readonly message: "File too large";
95
- readonly code: "FILE_TOO_LARGE";
96
- readonly status: 413;
97
- };
98
- readonly INVALID_TIME_VALUE: {
99
- readonly message: "Invalid time value";
100
- readonly code: "INVALID_TIME_VALUE";
101
- readonly status: 403;
102
- };
103
- };
104
- export type ErrorTypeKey = keyof typeof ERROR_TYPES;
105
- export declare function throwAppError(type: ErrorTypeKey, params?: AppErrorParams): never;
106
- export declare const throwValidationFailureError: (p?: AppErrorParams) => never;
107
- export declare const throwWrongCredentialsError: (p?: AppErrorParams) => never;
108
- export declare const throwRecordExistError: (p?: AppErrorParams) => never;
109
- export declare const throwRecordNotFoundError: (p?: AppErrorParams) => never;
110
- export declare const throwRecordNotSavedError: (p?: AppErrorParams) => never;
111
- export declare const throwLoginRequiredError: (p?: AppErrorParams) => never;
112
- export declare const throwUpdateFailedError: (p?: AppErrorParams) => never;
113
- export declare const throwTransactionFailedError: (p?: AppErrorParams) => never;
114
- export declare const throwUsedTokenError: (p?: AppErrorParams) => never;
115
- export declare const throwBadVisitorTokenError: (p?: AppErrorParams) => never;
116
- export declare const throwFileFormatNotSupportedError: (p?: AppErrorParams) => never;
117
- export declare const throwNotAuthorizedError: (p?: AppErrorParams) => never;
118
- export declare const throwBadInputError: (p?: AppErrorParams) => never;
119
- export declare const throwInputNotUuidError: (p?: AppErrorParams) => never;
120
- export declare const throwFileTooLargeError: (p?: AppErrorParams) => never;
121
- export declare const throwInvalidTimeValueError: (p?: AppErrorParams) => never;
122
- export declare function notFound404(req: Request, res: Response, _next: NextFunction): void;
123
- export declare function appErrorHandler(err: {
124
- message?: string;
125
- code?: string | number | null;
126
- userMessage?: string | null;
127
- details?: unknown;
128
- }, _req: Request, res: Response, _next: NextFunction): void;