Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix error handling #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 60 additions & 40 deletions handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,70 +8,90 @@ const todosDelete = require('./todos-delete.js');

module.exports.create = (event, context, callback) => {
todosCreate(event, (error, result) => {
const response = {
statusCode: 200,
headers: {
"Access-Control-Allow-Origin" : "*"
},
body: JSON.stringify(result),
};
if (error) {
context.fail(error)
} else {
const response = {
statusCode: 200,
headers: {
"Access-Control-Allow-Origin" : "*"
},
body: JSON.stringify(result),
};

context.succeed(response);
context.succeed(response);
}
});
};

module.exports.readAll = (event, context, callback) => {
todosReadAll(event, (error, result) => {
const response = {
statusCode: 200,
headers: {
"Access-Control-Allow-Origin" : "*"
},
body: JSON.stringify(result),
};
if (error) {
context.fail(error)
} else {
const response = {
statusCode: 200,
headers: {
"Access-Control-Allow-Origin" : "*"
},
body: JSON.stringify(result),
};

context.succeed(response);
context.succeed(response);
}
});
};

module.exports.readOne = (event, context, callback) => {
todosReadOne(event, (error, result) => {
const response = {
statusCode: 200,
headers: {
"Access-Control-Allow-Origin" : "*"
},
body: JSON.stringify(result),
};
if (error) {
context.fail(error)
} else {
const response = {
statusCode: 200,
headers: {
"Access-Control-Allow-Origin" : "*"
},
body: JSON.stringify(result),
};

context.succeed(response);
context.succeed(response);
}
});
};

module.exports.update = (event, context, callback) => {
todosUpdate(event, (error, result) => {
const response = {
statusCode: 200,
headers: {
"Access-Control-Allow-Origin" : "*"
},
body: JSON.stringify(result),
};
if (error) {
context.fail(error)
} else {
const response = {
statusCode: 200,
headers: {
"Access-Control-Allow-Origin" : "*"
},
body: JSON.stringify(result),
};

context.succeed(response);
context.succeed(response);
}
});
};

module.exports.delete = (event, context, callback) => {
todosDelete(event, (error, result) => {
const response = {
statusCode: 200,
headers: {
"Access-Control-Allow-Origin" : "*"
},
body: JSON.stringify(result),
};
if (error) {
context.fail(error)
} else {
const response = {
statusCode: 200,
headers: {
"Access-Control-Allow-Origin" : "*"
},
body: JSON.stringify(result),
};

context.succeed(response);
context.succeed(response);
}
});
};
2 changes: 1 addition & 1 deletion todos-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = (event, callback) => {

return dynamoDb.put(params, (error, data) => {
if (error) {
callback(error);
return callback(error);
}
callback(error, params.Item);
});
Expand Down
2 changes: 1 addition & 1 deletion todos-delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = (event, callback) => {

return dynamoDb.delete(params, (error, data) => {
if (error) {
callback(error);
return callback(error);
}
callback(error, params.Key);
});
Expand Down
2 changes: 1 addition & 1 deletion todos-read-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = (event, callback) => {

return dynamoDb.scan(params, (error, data) => {
if (error) {
callback(error);
return callback(error);
}
callback(error, data.Items);
});
Expand Down
2 changes: 1 addition & 1 deletion todos-read-one.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = (event, callback) => {

return dynamoDb.get(params, (error, data) => {
if (error) {
callback(error);
return callback(error);
}
callback(error, data.Item);
});
Expand Down
2 changes: 1 addition & 1 deletion todos-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = (event, callback) => {

return dynamoDb.put(params, (error, data) => {
if (error) {
callback(error);
return callback(error);
}
callback(error, params.Item);
});
Expand Down