oneday-core
Advanced tools
Comparing version 1.0.17 to 1.0.18
33
index.js
@@ -12,3 +12,6 @@ 'use strict'; | ||
const enums = require('./enum'); | ||
const {ValidationError, NotFoundError, ConflictError, InternalError} = require('./error'); | ||
module.exports = {ValidationError, NotFoundError, ConflictError, InternalError}; | ||
module.exports.saveEvent = saveEvent; | ||
@@ -36,2 +39,8 @@ module.exports.saveError = saveError; | ||
async function saveEvent(event, type) { // Saves the incoming copy of data to a table as is | ||
var requestId = uuid.v1(); | ||
if (event.requestContext.authorizer !== undefined && event.requestContext.authorizer.requestId !== undefined) { | ||
requestId = event.requestContext.authorizer.requestId; | ||
} | ||
const params = { | ||
@@ -42,3 +51,5 @@ TableName: process.env.incomingTable, | ||
function: type, | ||
event: event | ||
event: event, | ||
requestId: requestId, | ||
created: new Date().toISOString() | ||
}, | ||
@@ -66,3 +77,3 @@ }; | ||
message: message, | ||
timestamp: new Date().toISOString() | ||
created: new Date().toISOString() | ||
} | ||
@@ -79,10 +90,22 @@ }; | ||
async function handleValidation(message, validation, event, functionType) { | ||
class Error { | ||
} | ||
function handleValidation(validation) { | ||
if (validation.status === false) { | ||
const error = new Error('Missing params: (' + validation.props.toString() + '). '); | ||
await saveError(message, error, event, functionType); | ||
return {statusCode: 400}; | ||
error.statusCode = 400; | ||
throw error; | ||
} | ||
} | ||
async function generateErrorResponse(message, error, event, caller) { | ||
await saveError(message, error, event, caller); | ||
return { | ||
statusCode: error.statusCode !== undefined ? error.statusCode : 500, | ||
message: message | ||
}; | ||
} | ||
async function sendToQueue(body, queueName) { // Sends a message to the given queue | ||
@@ -89,0 +112,0 @@ try { |
{ | ||
"name": "oneday-core", | ||
"version": "1.0.17", | ||
"version": "1.0.18", | ||
"description": "Basic AWS util functions to ease development.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
17954
9
488