Last active
July 16, 2020 04:34
-
-
Save 5t33/440ebaacfbe1c38b19ce7ec912064a25 to your computer and use it in GitHub Desktop.
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
const Logger = require('./logger'); | |
const { handleError, handleResp, ApiError } = require('./utils'); | |
const { functionThatRejects, functionThatResolves, functionThatRejectsWith400 } = require('./anotherFile'); | |
const logger = Logger("trace"); | |
module.exports.handler = async ( event, context) => { | |
const log = logger.child({ | |
requestId: context.awsRequestId, | |
}); | |
if(event.requestPath === "/health_check" && event.method === "GET") { | |
return functionThatResolves() | |
.then(handleResp) | |
.catch(error => handleError(log, error)) | |
} else if (event.requestPath === "/respond_400" && event.method === "POST") { | |
return functionThatRejectsWith400() | |
.then(handleResp) | |
.catch(error => handleError(log, error)) | |
} else if(event.requestPath === "/throw_error" && event.method === "GET") { | |
return functionThatRejects() | |
.then(handleResp) | |
.catch(error => handleError(log, error)) | |
} else { | |
return handleError(logger, new ApiError(404, "404 Not Found")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment