Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(rest): log unexpected errors to console (#1058)
Revert back the recent change that moved error logs from console to debug logs. With this commit in place, when a request handler fails with a 5xx error, this error is printed via `console.error()` to notify people operating the application about a possible problem.
- Loading branch information
Showing
4 changed files
with
55 additions
and
23 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,27 @@ | ||
// Copyright IBM Corp. 2017,2018. All Rights Reserved. | ||
// Node module: @loopback/rest | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
import {ServerRequest} from 'http'; | ||
import {LogError} from '..'; | ||
|
||
export function createUnexpectedHttpErrorLogger( | ||
expectedStatusCode: number = 0, | ||
): LogError { | ||
return function logUnexpectedHttpError( | ||
err: Error, | ||
statusCode: number, | ||
req: ServerRequest, | ||
) { | ||
if (statusCode === expectedStatusCode) return; | ||
|
||
console.error( | ||
'Unhandled error in %s %s: %s %s', | ||
req.method, | ||
req.url, | ||
statusCode, | ||
err.stack || err, | ||
); | ||
}; | ||
} |
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