-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: send 404 for findById(), if resource is not found
send 404 for findById(), if resource is not found
- Loading branch information
Hage Yaapa
committed
Aug 28, 2018
1 parent
a408377
commit 8c5cf03
Showing
3 changed files
with
30 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as HttpErrors from 'http-errors'; | ||
|
||
export function throwNotFoundErrorWhenNull(model: null): never; | ||
export function throwNotFoundErrorWhenNull<T>(model: T): void; | ||
|
||
export function throwNotFoundErrorWhenNull<T>(model: T | null): T { | ||
if (model) return model; | ||
// WIP: don't mind these temporary hard-coded values | ||
const modelName = ''; | ||
const id = 2; | ||
const msg = `Unknown "${modelName}" id "${id}".`; | ||
const error = new HttpErrors.HttpError(msg); | ||
error.statusCode = error.status = 404; | ||
error.code = 'MODEL_NOT_FOUND'; | ||
throw error; | ||
} |