nodester 0.4.0 → 0.4.1
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.
|
@@ -151,12 +151,12 @@ function _withDefaultErrorProcessing(controller, options={}) {
|
|
|
151
151
|
switch(error.name) {
|
|
152
152
|
case UNAUTHORIZED_ERROR: {
|
|
153
153
|
statusCode = 401;
|
|
154
|
-
errorResponse.details = { message: 'Unauthorized' };
|
|
154
|
+
errorResponse.details = error?.details ?? { message: 'Unauthorized' };
|
|
155
155
|
break;
|
|
156
156
|
}
|
|
157
157
|
case NOT_FOUND_ERROR: {
|
|
158
158
|
statusCode = 404;
|
|
159
|
-
errorResponse.details = { message: errorMessage };
|
|
159
|
+
errorResponse.details = error?.details ?? { message: errorMessage };
|
|
160
160
|
break;
|
|
161
161
|
}
|
|
162
162
|
case NODESTER_QUERY_ERROR: {
|
|
@@ -166,7 +166,7 @@ function _withDefaultErrorProcessing(controller, options={}) {
|
|
|
166
166
|
}
|
|
167
167
|
case VALIDATION_ERROR: {
|
|
168
168
|
statusCode = 422;
|
|
169
|
-
errorResponse.details = error?.details;
|
|
169
|
+
errorResponse.details = error?.details ?? error?.details;
|
|
170
170
|
break;
|
|
171
171
|
}
|
|
172
172
|
case CONFLICT_ERROR: {
|
|
@@ -181,11 +181,11 @@ function _withDefaultErrorProcessing(controller, options={}) {
|
|
|
181
181
|
}
|
|
182
182
|
case INTERNAL_VALIDATION_ERROR: {
|
|
183
183
|
statusCode = 500;
|
|
184
|
-
errorResponse.details = { message: errorMessage };
|
|
184
|
+
errorResponse.details = error?.details ?? { message: errorMessage };
|
|
185
185
|
break;
|
|
186
186
|
}
|
|
187
187
|
default: {
|
|
188
|
-
errorResponse.details = { message: errorMessage };
|
|
188
|
+
errorResponse.details = error?.details ?? { message: errorMessage };
|
|
189
189
|
break;
|
|
190
190
|
}
|
|
191
191
|
}
|
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
|
|
6
6
|
'use strict';
|
|
7
7
|
|
|
8
|
+
// Constants:
|
|
9
|
+
const HTTP_CODES = require('nodester/http/codes');
|
|
10
|
+
const HTTP_CODE_DESCRIPTIONS = require('nodester/http/codes/descriptions');
|
|
11
|
+
|
|
8
12
|
const Params = require('nodester/params');
|
|
9
13
|
|
|
10
14
|
const log = require('nodester/loggers/dev');
|
|
@@ -184,8 +188,18 @@ async function _deleteOne(params) {
|
|
|
184
188
|
|
|
185
189
|
const count = await this.model.deleteOne(query);
|
|
186
190
|
|
|
191
|
+
// Model was not found:
|
|
192
|
+
if (count === 0) {
|
|
193
|
+
const err = new Error(HTTP_CODE_DESCRIPTIONS.NOT_FOUND);
|
|
194
|
+
err.statusCode = HTTP_CODES.NOT_FOUND;
|
|
195
|
+
err.details = {
|
|
196
|
+
message: 'Resource not found. Nothing was deleted.'
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
throw err;
|
|
200
|
+
}
|
|
201
|
+
|
|
187
202
|
const result = {
|
|
188
|
-
success: count > 0,
|
|
189
203
|
count: count
|
|
190
204
|
};
|
|
191
205
|
|
|
@@ -195,7 +209,12 @@ async function _deleteOne(params) {
|
|
|
195
209
|
return Promise.resolve(result);
|
|
196
210
|
}
|
|
197
211
|
catch(error) {
|
|
198
|
-
|
|
212
|
+
|
|
213
|
+
// 404 will not be logged:
|
|
214
|
+
if (error.statusCode !== HTTP_CODES.NOT_FOUND) {
|
|
215
|
+
log.error(`${ this.name }.deleteOne error:`, error);
|
|
216
|
+
}
|
|
217
|
+
|
|
199
218
|
return Promise.reject(error);
|
|
200
219
|
}
|
|
201
220
|
}
|
|
@@ -389,7 +389,6 @@ function _traverseIncludedOrders(resultQuery, rootModel) {
|
|
|
389
389
|
for (let i=0; i < resultQuery.include.length; i++) {
|
|
390
390
|
const include = resultQuery.include[i];
|
|
391
391
|
|
|
392
|
-
console.log({ irder: include?.order });
|
|
393
392
|
if (!include?.order) {
|
|
394
393
|
continue;
|
|
395
394
|
}
|