Skip to content

Instantly share code, notes, and snippets.

@5t33
Last active July 16, 2020 04:34
Show Gist options
  • Save 5t33/440ebaacfbe1c38b19ce7ec912064a25 to your computer and use it in GitHub Desktop.
Save 5t33/440ebaacfbe1c38b19ce7ec912064a25 to your computer and use it in GitHub Desktop.
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