@nymphjs/server 1.0.0-beta.10 → 1.0.0-beta.11
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.
- package/CHANGELOG.md +6 -0
- package/dist/HttpError.d.ts +5 -0
- package/dist/HttpError.js +13 -0
- package/dist/HttpError.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +144 -66
- package/dist/index.js.map +1 -1
- package/dist/index.test.js +30 -2
- package/dist/index.test.js.map +1 -1
- package/dist/testArtifacts.d.ts +4 -0
- package/dist/testArtifacts.js +15 -0
- package/dist/testArtifacts.js.map +1 -1
- package/package.json +12 -12
- package/src/HttpError.ts +12 -0
- package/src/index.test.ts +32 -2
- package/src/index.ts +151 -71
- package/src/testArtifacts.ts +20 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.0.0-beta.11](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.10...v1.0.0-beta.11) (2023-02-27)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- allow customizing HTTP status codes in response from server called methods ([8c5c3d4](https://github.com/sciactive/nymphjs/commit/8c5c3d4af741edabc1a8947aaebf026ba546c46a))
|
|
11
|
+
|
|
6
12
|
# [1.0.0-beta.10](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.9...v1.0.0-beta.10) (2023-01-19)
|
|
7
13
|
|
|
8
14
|
**Note:** Version bump only for package @nymphjs/server
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpError = void 0;
|
|
4
|
+
class HttpError extends Error {
|
|
5
|
+
constructor(message, status, statusText) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'HttpError';
|
|
8
|
+
this.status = status;
|
|
9
|
+
this.statusText = statusText;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.HttpError = HttpError;
|
|
13
|
+
//# sourceMappingURL=HttpError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpError.js","sourceRoot":"","sources":["../src/HttpError.ts"],"names":[],"mappings":";;;AAAA,MAAa,SAAU,SAAQ,KAAK;IAIlC,YAAY,OAAe,EAAE,MAAe,EAAE,UAAmB;QAC/D,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AAXD,8BAWC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { OptionsJson } from 'body-parser';
|
|
2
2
|
import { Nymph } from '@nymphjs/nymph';
|
|
3
|
+
import { HttpError } from './HttpError';
|
|
4
|
+
export { HttpError };
|
|
3
5
|
export default function createServer(nymph: Nymph, { jsonOptions }?: {
|
|
4
6
|
jsonOptions?: OptionsJson;
|
|
5
7
|
}): import("express-serve-static-core").Express;
|
package/dist/index.js
CHANGED
|
@@ -3,10 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.HttpError = void 0;
|
|
6
7
|
const express_1 = __importDefault(require("express"));
|
|
7
8
|
const cookie_parser_1 = __importDefault(require("cookie-parser"));
|
|
8
9
|
const nymph_1 = require("@nymphjs/nymph");
|
|
9
10
|
const nymph_2 = require("@nymphjs/nymph");
|
|
11
|
+
const HttpError_1 = require("./HttpError");
|
|
12
|
+
Object.defineProperty(exports, "HttpError", { enumerable: true, get: function () { return HttpError_1.HttpError; } });
|
|
10
13
|
const NOT_FOUND_ERROR = 'Entity is not found.';
|
|
11
14
|
function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
12
15
|
const rest = (0, express_1.default)();
|
|
@@ -24,7 +27,7 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
24
27
|
response.locals.nymph.tilmeld.authenticate();
|
|
25
28
|
}
|
|
26
29
|
catch (e) {
|
|
27
|
-
httpError(response, 500,
|
|
30
|
+
httpError(response, 500, e);
|
|
28
31
|
return;
|
|
29
32
|
}
|
|
30
33
|
}
|
|
@@ -38,7 +41,7 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
38
41
|
response.locals.nymph.tilmeld.clearSession();
|
|
39
42
|
}
|
|
40
43
|
catch (e) {
|
|
41
|
-
httpError(response, 500,
|
|
44
|
+
httpError(response, 500, e);
|
|
42
45
|
return;
|
|
43
46
|
}
|
|
44
47
|
}
|
|
@@ -71,21 +74,21 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
71
74
|
try {
|
|
72
75
|
const { action, data } = getActionData(request);
|
|
73
76
|
if (['entity', 'entities', 'uid'].indexOf(action) === -1) {
|
|
74
|
-
httpError(response, 400
|
|
77
|
+
httpError(response, 400);
|
|
75
78
|
return;
|
|
76
79
|
}
|
|
77
80
|
if (['entity', 'entities'].indexOf(action) !== -1) {
|
|
78
81
|
if (!Array.isArray(data)) {
|
|
79
|
-
httpError(response, 400
|
|
82
|
+
httpError(response, 400);
|
|
80
83
|
return;
|
|
81
84
|
}
|
|
82
85
|
const count = data.length;
|
|
83
86
|
if (count < 1 || typeof data[0] !== 'object') {
|
|
84
|
-
httpError(response, 400
|
|
87
|
+
httpError(response, 400);
|
|
85
88
|
return;
|
|
86
89
|
}
|
|
87
90
|
if (!('class' in data[0])) {
|
|
88
|
-
httpError(response, 400
|
|
91
|
+
httpError(response, 400);
|
|
89
92
|
return;
|
|
90
93
|
}
|
|
91
94
|
let [options, ...selectors] = data;
|
|
@@ -94,7 +97,7 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
94
97
|
EntityClass = response.locals.nymph.getEntityClass(data[0].class);
|
|
95
98
|
}
|
|
96
99
|
catch (e) {
|
|
97
|
-
httpError(response, 400,
|
|
100
|
+
httpError(response, 400, e);
|
|
98
101
|
return;
|
|
99
102
|
}
|
|
100
103
|
options.class = EntityClass;
|
|
@@ -111,13 +114,13 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
111
114
|
}
|
|
112
115
|
}
|
|
113
116
|
catch (e) {
|
|
114
|
-
httpError(response, 500,
|
|
117
|
+
httpError(response, 500, e);
|
|
115
118
|
return;
|
|
116
119
|
}
|
|
117
120
|
if (result == null || (Array.isArray(result) && result.length === 0)) {
|
|
118
121
|
if (action === 'entity' ||
|
|
119
122
|
response.locals.nymph.config.emptyListError) {
|
|
120
|
-
httpError(response, 404
|
|
123
|
+
httpError(response, 404);
|
|
121
124
|
return;
|
|
122
125
|
}
|
|
123
126
|
}
|
|
@@ -126,12 +129,12 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
126
129
|
}
|
|
127
130
|
else {
|
|
128
131
|
if (typeof data !== 'string') {
|
|
129
|
-
httpError(response, 400
|
|
132
|
+
httpError(response, 400);
|
|
130
133
|
return;
|
|
131
134
|
}
|
|
132
135
|
if (response.locals.nymph.tilmeld) {
|
|
133
136
|
if (!response.locals.nymph.tilmeld.checkClientUIDPermissions(data, nymph_1.TilmeldAccessLevels.READ_ACCESS)) {
|
|
134
|
-
httpError(response, 403
|
|
137
|
+
httpError(response, 403);
|
|
135
138
|
return;
|
|
136
139
|
}
|
|
137
140
|
}
|
|
@@ -140,15 +143,15 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
140
143
|
result = await response.locals.nymph.getUID(data);
|
|
141
144
|
}
|
|
142
145
|
catch (e) {
|
|
143
|
-
httpError(response, 500,
|
|
146
|
+
httpError(response, 500, e);
|
|
144
147
|
return;
|
|
145
148
|
}
|
|
146
149
|
if (result === null) {
|
|
147
|
-
httpError(response, 404
|
|
150
|
+
httpError(response, 404);
|
|
148
151
|
return;
|
|
149
152
|
}
|
|
150
153
|
else if (typeof result !== 'number') {
|
|
151
|
-
httpError(response, 500
|
|
154
|
+
httpError(response, 500);
|
|
152
155
|
return;
|
|
153
156
|
}
|
|
154
157
|
response.setHeader('Content-Type', 'text/plain');
|
|
@@ -156,7 +159,7 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
156
159
|
}
|
|
157
160
|
}
|
|
158
161
|
catch (e) {
|
|
159
|
-
httpError(response, 500,
|
|
162
|
+
httpError(response, 500, e);
|
|
160
163
|
return;
|
|
161
164
|
}
|
|
162
165
|
});
|
|
@@ -165,7 +168,7 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
165
168
|
const { action, data: dataConst } = getActionData(request);
|
|
166
169
|
let data = dataConst;
|
|
167
170
|
if (['entity', 'entities', 'uid', 'method'].indexOf(action) === -1) {
|
|
168
|
-
httpError(response, 400
|
|
171
|
+
httpError(response, 400);
|
|
169
172
|
return;
|
|
170
173
|
}
|
|
171
174
|
if (['entity', 'entities'].indexOf(action) !== -1) {
|
|
@@ -231,19 +234,19 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
231
234
|
}
|
|
232
235
|
if (!hadSuccess) {
|
|
233
236
|
if (invalidRequest) {
|
|
234
|
-
httpError(response, 400,
|
|
237
|
+
httpError(response, 400, lastException);
|
|
235
238
|
return;
|
|
236
239
|
}
|
|
237
240
|
else if (conflict) {
|
|
238
|
-
httpError(response, 409
|
|
241
|
+
httpError(response, 409);
|
|
239
242
|
return;
|
|
240
243
|
}
|
|
241
244
|
else if (notfound) {
|
|
242
|
-
httpError(response, 404
|
|
245
|
+
httpError(response, 404);
|
|
243
246
|
return;
|
|
244
247
|
}
|
|
245
248
|
else {
|
|
246
|
-
httpError(response, 500,
|
|
249
|
+
httpError(response, 500, lastException);
|
|
247
250
|
return;
|
|
248
251
|
}
|
|
249
252
|
}
|
|
@@ -258,7 +261,7 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
258
261
|
}
|
|
259
262
|
else if (action === 'method') {
|
|
260
263
|
if (!Array.isArray(data.params)) {
|
|
261
|
-
httpError(response, 400
|
|
264
|
+
httpError(response, 400);
|
|
262
265
|
return;
|
|
263
266
|
}
|
|
264
267
|
const params = referencesToEntities([...data.params], response.locals.nymph);
|
|
@@ -268,20 +271,20 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
268
271
|
EntityClass = response.locals.nymph.getEntityClass(data.class);
|
|
269
272
|
}
|
|
270
273
|
catch (e) {
|
|
271
|
-
httpError(response, 400
|
|
274
|
+
httpError(response, 400);
|
|
272
275
|
return;
|
|
273
276
|
}
|
|
274
277
|
if (EntityClass.clientEnabledStaticMethods.indexOf(data.method) === -1) {
|
|
275
|
-
httpError(response, 403
|
|
278
|
+
httpError(response, 403);
|
|
276
279
|
return;
|
|
277
280
|
}
|
|
278
281
|
if (!(data.method in EntityClass)) {
|
|
279
|
-
httpError(response, 400
|
|
282
|
+
httpError(response, 400);
|
|
280
283
|
return;
|
|
281
284
|
}
|
|
282
285
|
const method = EntityClass[data.method];
|
|
283
286
|
if (typeof method !== 'function') {
|
|
284
|
-
httpError(response, 400
|
|
287
|
+
httpError(response, 400);
|
|
285
288
|
return;
|
|
286
289
|
}
|
|
287
290
|
try {
|
|
@@ -295,7 +298,7 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
295
298
|
response.send({ return: ret });
|
|
296
299
|
}
|
|
297
300
|
catch (e) {
|
|
298
|
-
httpError(response, 500,
|
|
301
|
+
httpError(response, 500, e);
|
|
299
302
|
return;
|
|
300
303
|
}
|
|
301
304
|
}
|
|
@@ -306,30 +309,30 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
306
309
|
}
|
|
307
310
|
catch (e) {
|
|
308
311
|
if (e instanceof nymph_1.EntityConflictError) {
|
|
309
|
-
httpError(response, 409
|
|
312
|
+
httpError(response, 409);
|
|
310
313
|
}
|
|
311
314
|
else if (e.message === NOT_FOUND_ERROR) {
|
|
312
|
-
httpError(response, 404,
|
|
315
|
+
httpError(response, 404, e);
|
|
313
316
|
}
|
|
314
317
|
else if (e instanceof nymph_1.InvalidParametersError) {
|
|
315
|
-
httpError(response, 400,
|
|
318
|
+
httpError(response, 400, e);
|
|
316
319
|
}
|
|
317
320
|
else {
|
|
318
|
-
httpError(response, 500,
|
|
321
|
+
httpError(response, 500, e);
|
|
319
322
|
}
|
|
320
323
|
return;
|
|
321
324
|
}
|
|
322
325
|
if (data.entity.guid && !entity.guid) {
|
|
323
|
-
httpError(response, 400
|
|
326
|
+
httpError(response, 400);
|
|
324
327
|
return;
|
|
325
328
|
}
|
|
326
329
|
if (entity.$getClientEnabledMethods().indexOf(data.method) === -1) {
|
|
327
|
-
httpError(response, 403
|
|
330
|
+
httpError(response, 403);
|
|
328
331
|
return;
|
|
329
332
|
}
|
|
330
333
|
if (!(data.method in entity) ||
|
|
331
334
|
typeof entity[data.method] !== 'function') {
|
|
332
|
-
httpError(response, 400
|
|
335
|
+
httpError(response, 400);
|
|
333
336
|
return;
|
|
334
337
|
}
|
|
335
338
|
try {
|
|
@@ -348,19 +351,19 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
348
351
|
}
|
|
349
352
|
}
|
|
350
353
|
catch (e) {
|
|
351
|
-
httpError(response, 500,
|
|
354
|
+
httpError(response, 500, e);
|
|
352
355
|
return;
|
|
353
356
|
}
|
|
354
357
|
}
|
|
355
358
|
}
|
|
356
359
|
else {
|
|
357
360
|
if (typeof data !== 'string') {
|
|
358
|
-
httpError(response, 400
|
|
361
|
+
httpError(response, 400);
|
|
359
362
|
return;
|
|
360
363
|
}
|
|
361
364
|
if (response.locals.nymph.tilmeld) {
|
|
362
365
|
if (!response.locals.nymph.tilmeld.checkClientUIDPermissions(data, nymph_1.TilmeldAccessLevels.WRITE_ACCESS)) {
|
|
363
|
-
httpError(response, 403
|
|
366
|
+
httpError(response, 403);
|
|
364
367
|
return;
|
|
365
368
|
}
|
|
366
369
|
}
|
|
@@ -369,11 +372,11 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
369
372
|
result = await response.locals.nymph.newUID(data);
|
|
370
373
|
}
|
|
371
374
|
catch (e) {
|
|
372
|
-
httpError(response, 500,
|
|
375
|
+
httpError(response, 500, e);
|
|
373
376
|
return;
|
|
374
377
|
}
|
|
375
378
|
if (typeof result !== 'number') {
|
|
376
|
-
httpError(response, 500
|
|
379
|
+
httpError(response, 500);
|
|
377
380
|
return;
|
|
378
381
|
}
|
|
379
382
|
response.status(201);
|
|
@@ -382,7 +385,7 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
382
385
|
}
|
|
383
386
|
}
|
|
384
387
|
catch (e) {
|
|
385
|
-
httpError(response, 500,
|
|
388
|
+
httpError(response, 500, e);
|
|
386
389
|
return;
|
|
387
390
|
}
|
|
388
391
|
});
|
|
@@ -390,13 +393,13 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
390
393
|
try {
|
|
391
394
|
const { action, data } = getActionData(request);
|
|
392
395
|
if (['entity', 'entities', 'uid'].indexOf(action) === -1) {
|
|
393
|
-
httpError(response, 400
|
|
396
|
+
httpError(response, 400);
|
|
394
397
|
return;
|
|
395
398
|
}
|
|
396
399
|
await doPutOrPatch(response, action, data, false);
|
|
397
400
|
}
|
|
398
401
|
catch (e) {
|
|
399
|
-
httpError(response, 500,
|
|
402
|
+
httpError(response, 500, e);
|
|
400
403
|
return;
|
|
401
404
|
}
|
|
402
405
|
});
|
|
@@ -404,25 +407,25 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
404
407
|
try {
|
|
405
408
|
const { action, data } = getActionData(request);
|
|
406
409
|
if (['entity', 'entities'].indexOf(action) === -1) {
|
|
407
|
-
httpError(response, 400
|
|
410
|
+
httpError(response, 400);
|
|
408
411
|
return;
|
|
409
412
|
}
|
|
410
413
|
await doPutOrPatch(response, action, data, true);
|
|
411
414
|
}
|
|
412
415
|
catch (e) {
|
|
413
|
-
httpError(response, 500,
|
|
416
|
+
httpError(response, 500, e);
|
|
414
417
|
return;
|
|
415
418
|
}
|
|
416
419
|
});
|
|
417
420
|
async function doPutOrPatch(response, action, data, patch) {
|
|
418
421
|
if (action === 'uid') {
|
|
419
422
|
if (typeof data.name !== 'string' || typeof data.value !== 'number') {
|
|
420
|
-
httpError(response, 400
|
|
423
|
+
httpError(response, 400);
|
|
421
424
|
return;
|
|
422
425
|
}
|
|
423
426
|
if (response.locals.nymph.tilmeld) {
|
|
424
427
|
if (!response.locals.nymph.tilmeld.checkClientUIDPermissions(data.name, nymph_1.TilmeldAccessLevels.FULL_ACCESS)) {
|
|
425
|
-
httpError(response, 403
|
|
428
|
+
httpError(response, 403);
|
|
426
429
|
return;
|
|
427
430
|
}
|
|
428
431
|
}
|
|
@@ -431,11 +434,11 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
431
434
|
result = await response.locals.nymph.setUID(data.name, data.value);
|
|
432
435
|
}
|
|
433
436
|
catch (e) {
|
|
434
|
-
httpError(response, 500,
|
|
437
|
+
httpError(response, 500, e);
|
|
435
438
|
return;
|
|
436
439
|
}
|
|
437
440
|
if (!result) {
|
|
438
|
-
httpError(response, 500
|
|
441
|
+
httpError(response, 500);
|
|
439
442
|
return;
|
|
440
443
|
}
|
|
441
444
|
response.status(200);
|
|
@@ -505,16 +508,16 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
505
508
|
}
|
|
506
509
|
if (!hadSuccess) {
|
|
507
510
|
if (invalidRequest) {
|
|
508
|
-
httpError(response, 400,
|
|
511
|
+
httpError(response, 400, lastException);
|
|
509
512
|
}
|
|
510
513
|
else if (conflict) {
|
|
511
|
-
httpError(response, 409
|
|
514
|
+
httpError(response, 409);
|
|
512
515
|
}
|
|
513
516
|
else if (notfound) {
|
|
514
|
-
httpError(response, 404
|
|
517
|
+
httpError(response, 404);
|
|
515
518
|
}
|
|
516
519
|
else {
|
|
517
|
-
httpError(response, 500,
|
|
520
|
+
httpError(response, 500, lastException);
|
|
518
521
|
}
|
|
519
522
|
return;
|
|
520
523
|
}
|
|
@@ -533,7 +536,7 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
533
536
|
const { action, data: dataConst } = getActionData(request);
|
|
534
537
|
let data = dataConst;
|
|
535
538
|
if (['entity', 'entities', 'uid'].indexOf(action) === -1) {
|
|
536
|
-
httpError(response, 400
|
|
539
|
+
httpError(response, 400);
|
|
537
540
|
return;
|
|
538
541
|
}
|
|
539
542
|
if (['entity', 'entities'].indexOf(action) !== -1) {
|
|
@@ -542,7 +545,6 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
542
545
|
}
|
|
543
546
|
const deleted = [];
|
|
544
547
|
let failures = false;
|
|
545
|
-
let hadSuccess = false;
|
|
546
548
|
let invalidRequest = false;
|
|
547
549
|
let notfound = false;
|
|
548
550
|
let lastException = null;
|
|
@@ -577,7 +579,6 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
577
579
|
try {
|
|
578
580
|
if (await entity.$delete()) {
|
|
579
581
|
deleted.push(entData.guid);
|
|
580
|
-
hadSuccess = true;
|
|
581
582
|
}
|
|
582
583
|
else {
|
|
583
584
|
failures = true;
|
|
@@ -590,13 +591,13 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
590
591
|
}
|
|
591
592
|
if (deleted.length === 0) {
|
|
592
593
|
if (invalidRequest || !failures) {
|
|
593
|
-
httpError(response, 400,
|
|
594
|
+
httpError(response, 400, lastException);
|
|
594
595
|
}
|
|
595
596
|
else if (notfound) {
|
|
596
|
-
httpError(response, 404
|
|
597
|
+
httpError(response, 404);
|
|
597
598
|
}
|
|
598
599
|
else {
|
|
599
|
-
httpError(response, 500,
|
|
600
|
+
httpError(response, 500, lastException);
|
|
600
601
|
}
|
|
601
602
|
return;
|
|
602
603
|
}
|
|
@@ -611,12 +612,12 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
611
612
|
}
|
|
612
613
|
else {
|
|
613
614
|
if (typeof data !== 'string') {
|
|
614
|
-
httpError(response, 400
|
|
615
|
+
httpError(response, 400);
|
|
615
616
|
return;
|
|
616
617
|
}
|
|
617
618
|
if (response.locals.nymph.tilmeld) {
|
|
618
619
|
if (!response.locals.nymph.tilmeld.checkClientUIDPermissions(data, nymph_1.TilmeldAccessLevels.FULL_ACCESS)) {
|
|
619
|
-
httpError(response, 403
|
|
620
|
+
httpError(response, 403);
|
|
620
621
|
return;
|
|
621
622
|
}
|
|
622
623
|
}
|
|
@@ -625,11 +626,11 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
625
626
|
result = await response.locals.nymph.deleteUID(data);
|
|
626
627
|
}
|
|
627
628
|
catch (e) {
|
|
628
|
-
httpError(response, 500,
|
|
629
|
+
httpError(response, 500, e);
|
|
629
630
|
return;
|
|
630
631
|
}
|
|
631
632
|
if (!result) {
|
|
632
|
-
httpError(response, 500
|
|
633
|
+
httpError(response, 500);
|
|
633
634
|
return;
|
|
634
635
|
}
|
|
635
636
|
response.status(200);
|
|
@@ -638,7 +639,7 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
638
639
|
}
|
|
639
640
|
}
|
|
640
641
|
catch (e) {
|
|
641
|
-
httpError(response, 500,
|
|
642
|
+
httpError(response, 500, e);
|
|
642
643
|
return;
|
|
643
644
|
}
|
|
644
645
|
});
|
|
@@ -691,14 +692,22 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
691
692
|
}
|
|
692
693
|
return item;
|
|
693
694
|
}
|
|
694
|
-
function httpError(res,
|
|
695
|
+
function httpError(res, defaultStatusCode, error) {
|
|
696
|
+
const status = error?.status || defaultStatusCode;
|
|
697
|
+
const statusText = error?.statusText ||
|
|
698
|
+
(error?.status == null
|
|
699
|
+
? statusDescriptions[defaultStatusCode]
|
|
700
|
+
: error.status in statusDescriptions &&
|
|
701
|
+
statusDescriptions[error.status]) ||
|
|
702
|
+
'Internal Server Error';
|
|
695
703
|
if (!res.headersSent) {
|
|
696
|
-
res.status(
|
|
704
|
+
res.status(status);
|
|
697
705
|
res.setHeader('Content-Type', 'application/json');
|
|
698
706
|
}
|
|
699
707
|
if (error) {
|
|
700
708
|
res.send({
|
|
701
|
-
textStatus: `${
|
|
709
|
+
textStatus: `${status} ${statusText}`,
|
|
710
|
+
statusText,
|
|
702
711
|
message: error.message,
|
|
703
712
|
error,
|
|
704
713
|
...(process.env.NODE_ENV !== 'production'
|
|
@@ -707,10 +716,79 @@ function createServer(nymph, { jsonOptions = {} } = {}) {
|
|
|
707
716
|
});
|
|
708
717
|
}
|
|
709
718
|
else {
|
|
710
|
-
res.send({
|
|
719
|
+
res.send({
|
|
720
|
+
textStatus: `${status} ${statusText}`,
|
|
721
|
+
statusText,
|
|
722
|
+
message: statusText,
|
|
723
|
+
});
|
|
711
724
|
}
|
|
712
725
|
}
|
|
713
726
|
return rest;
|
|
714
727
|
}
|
|
715
728
|
exports.default = createServer;
|
|
729
|
+
const statusDescriptions = {
|
|
730
|
+
100: 'Continue',
|
|
731
|
+
101: 'Switching Protocols',
|
|
732
|
+
102: 'Processing',
|
|
733
|
+
103: 'Early Hints',
|
|
734
|
+
200: 'OK',
|
|
735
|
+
201: 'Created',
|
|
736
|
+
202: 'Accepted',
|
|
737
|
+
203: 'Non-Authoritative Information',
|
|
738
|
+
204: 'No Content',
|
|
739
|
+
205: 'Reset Content',
|
|
740
|
+
206: 'Partial Content',
|
|
741
|
+
207: 'Multi-Status',
|
|
742
|
+
208: 'Already Reported',
|
|
743
|
+
226: 'IM Used',
|
|
744
|
+
300: 'Multiple Choices',
|
|
745
|
+
301: 'Moved Permanently',
|
|
746
|
+
302: 'Found',
|
|
747
|
+
303: 'See Other',
|
|
748
|
+
304: 'Not Modified',
|
|
749
|
+
305: 'Use Proxy',
|
|
750
|
+
306: 'Switch Proxy',
|
|
751
|
+
307: 'Temporary Redirect',
|
|
752
|
+
308: 'Permanent Redirect',
|
|
753
|
+
400: 'Bad Request',
|
|
754
|
+
401: 'Unauthorized',
|
|
755
|
+
402: 'Payment Required',
|
|
756
|
+
403: 'Forbidden',
|
|
757
|
+
404: 'Not Found',
|
|
758
|
+
405: 'Method Not Allowed',
|
|
759
|
+
406: 'Not Acceptable',
|
|
760
|
+
407: 'Proxy Authentication Required',
|
|
761
|
+
408: 'Request Timeout',
|
|
762
|
+
409: 'Conflict',
|
|
763
|
+
410: 'Gone',
|
|
764
|
+
411: 'Length Required',
|
|
765
|
+
412: 'Precondition Failed',
|
|
766
|
+
413: 'Payload Too Large',
|
|
767
|
+
414: 'URI Too Long',
|
|
768
|
+
415: 'Unsupported Media Type',
|
|
769
|
+
416: 'Range Not Satisfiable',
|
|
770
|
+
417: 'Expectation Failed',
|
|
771
|
+
418: "I'm a teapot",
|
|
772
|
+
421: 'Misdirected Request',
|
|
773
|
+
422: 'Unprocessable Entity',
|
|
774
|
+
423: 'Locked',
|
|
775
|
+
424: 'Failed Dependency',
|
|
776
|
+
425: 'Too Early',
|
|
777
|
+
426: 'Upgrade Required',
|
|
778
|
+
428: 'Precondition Required',
|
|
779
|
+
429: 'Too Many Requests',
|
|
780
|
+
431: 'Request Header Fields Too Large',
|
|
781
|
+
451: 'Unavailable For Legal Reasons',
|
|
782
|
+
500: 'Internal Server Error',
|
|
783
|
+
501: 'Not Implemented',
|
|
784
|
+
502: 'Bad Gateway',
|
|
785
|
+
503: 'Service Unavailable',
|
|
786
|
+
504: 'Gateway Timeout',
|
|
787
|
+
505: 'HTTP Version Not Supported',
|
|
788
|
+
506: 'Variant Also Negotiates',
|
|
789
|
+
507: 'Insufficient Storage',
|
|
790
|
+
508: 'Loop Detected',
|
|
791
|
+
510: 'Not Extended',
|
|
792
|
+
511: 'Network Authentication Required',
|
|
793
|
+
};
|
|
716
794
|
//# sourceMappingURL=index.js.map
|