Skip to content

Instantly share code, notes, and snippets.

@5t33
Last active July 16, 2020 04:33
Show Gist options
  • Save 5t33/07ffbfbe51b3d36678042c1024229721 to your computer and use it in GitHub Desktop.
Save 5t33/07ffbfbe51b3d36678042c1024229721 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("info");
module.exports.handler = async ( event, context) => {
const log = logger.child({
requestId: context.awsRequestId,
});
if(event.path === "/health_check" && event.httpMethod === "GET") {
return functionThatResolves()
.then(handleResp)
.catch(error => handleError(log, error))
} else if (event.path === "/respond_400" && event.httpMethod === "GET") {
return functionThatRejectsWith400()
.then(handleResp)
.catch(error => handleError(logger, error))
} else if(event.path === "/throw_error" && event.httpMethod === "GET") {
return functionThatRejects()
.then(handleResp)
.catch(error => handleError(logger, 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