Skip to content

Commit 9b70134

Browse files
committed
Change order of else-if null/undefined check
1 parent 0e64ffe commit 9b70134

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

src/driver/express/ExpressDriver.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,29 +278,29 @@ export class ExpressDriver extends BaseDriver implements Driver {
278278
options.next();
279279
});
280280
}
281-
else if (result != null) { // send regular result
282-
if (action.isJsonTyped) {
283-
options.response.json(result);
284-
} else {
285-
options.response.send(result);
286-
}
287-
options.next();
288-
}
289281
else if (result === undefined) { // throw NotFoundError on undefined response
290282
const notFoundError = new NotFoundError();
291283
if (action.undefinedResultCode) {
292284
notFoundError.httpCode = action.undefinedResultCode as number;
293285
}
294286
throw notFoundError;
295287
}
296-
else { // send null response
288+
else if (result === null) { // send null response
297289
if (action.isJsonTyped) {
298290
options.response.json(null);
299291
} else {
300292
options.response.send(null);
301293
}
302294
options.next();
303295
}
296+
else { // send regular result
297+
if (action.isJsonTyped) {
298+
options.response.json(result);
299+
} else {
300+
options.response.send(result);
301+
}
302+
options.next();
303+
}
304304
}
305305

306306
/**

src/driver/koa/KoaDriver.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -247,36 +247,36 @@ export class KoaDriver extends BaseDriver implements Driver {
247247

248248
return options.next();
249249
}
250-
else if (result != null) { // send regular result
251-
if (result instanceof Object) {
252-
options.response.body = result;
253-
} else {
254-
options.response.body = result;
255-
}
256-
257-
return options.next();
258-
}
259250
else if (result === undefined) { // throw NotFoundError on undefined response
260251
const notFoundError = new NotFoundError();
261252
if (action.undefinedResultCode) {
262253
notFoundError.httpCode = action.undefinedResultCode as number;
263254
}
264255
throw notFoundError;
265256
}
266-
else { // send null response
257+
else if (result === null) { // send null response
267258
if (action.isJsonTyped) {
268259
options.response.body = null;
269260
} else {
270261
options.response.body = null;
271262
}
272-
263+
273264
// Setting `null` as a `response.body` means to koa that there is no content to return
274265
// so we must reset the status codes here.
275266
if (action.nullResultCode) {
276267
options.response.status = action.nullResultCode;
277268
} else {
278269
options.response.status = 204;
279270
}
271+
272+
return options.next();
273+
}
274+
else { // send regular result
275+
if (result instanceof Object) {
276+
options.response.body = result;
277+
} else {
278+
options.response.body = result;
279+
}
280280

281281
return options.next();
282282
}

0 commit comments

Comments
 (0)