-
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.
refactor: move unexpectedhttperrorlogger to testlab
- Loading branch information
1 parent
f8ecd49
commit 798c416
Showing
6 changed files
with
97 additions
and
32 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
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,35 @@ | ||
// Copyright IBM Corp. 2019. All Rights Reserved. | ||
// Node module: @loopback/testlab | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
import {Request} from 'express'; | ||
import {IncomingMessage} from 'http'; | ||
|
||
/** | ||
* Creates a Logger that logs an Error if the HTTP status code is not expected | ||
* | ||
* @param expectedStatusCode HTTP status code that is expected | ||
*/ | ||
export function createUnexpectedHttpErrorLogger( | ||
expectedStatusCode?: number, | ||
): LogError { | ||
return function logUnexpectedHttpError( | ||
err: Error, | ||
statusCode: number, | ||
req: IncomingMessage, | ||
) { | ||
if (statusCode === expectedStatusCode) return; | ||
|
||
/* istanbul ignore next */ | ||
console.error( | ||
'Unhandled error in %s %s: %s %s', | ||
req.method, | ||
req.url, | ||
statusCode, | ||
err.stack || err, | ||
); | ||
}; | ||
} | ||
|
||
type LogError = (err: Error, statusCode: number, request: Request) => void; |
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