Skip to content

Commit

Permalink
handles errors with hapi-error #32
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcarlisle committed Oct 6, 2016
1 parent 561b0ff commit ebdf9e4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion examples/sdk-upload/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ var AWS = require('aws-sdk')
var crypto = require('crypto')
// we use path to add the relative file extension
var path = require('path')
// hapi-error to handle our errors
var handleError = require('hapi-error').handleError

// assign our region from our environment variables
AWS.config.region = process.env.AWS_S3_REGION
Expand All @@ -105,7 +107,7 @@ function upload (file, filename, callback) {
var params = {Bucket: bucket, Key: filenameHex, Body: file}
// SDK upload to S3
s3Bucket.upload(params, function (err, data) {
if (err) console.log(err, data)
handleError(err, data)
// callback with the data that gets returned from S3
else callback(null, data)
})
Expand Down
3 changes: 2 additions & 1 deletion examples/sdk-upload/src/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ require('env2')('./.env')
var AWS = require('aws-sdk')
var crypto = require('crypto')
var path = require('path')
var handleError = require('hapi-error').handleError

AWS.config.region = process.env.AWS_S3_REGION

Expand All @@ -14,7 +15,7 @@ function upload (file, filename, callback) {
var s3Bucket = new AWS.S3({params: {Bucket: bucket}})
var params = {Bucket: bucket, Key: filenameHex, Body: file}
s3Bucket.upload(params, function (err, data) {
console.log(err, data)
handleError(err, data)
callback(null, data)
})
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"aws-sdk": "^2.6.5",
"env2": "^2.1.1",
"hapi": "^15.0.3",
"hapi-error": "^1.4.1",
"inert": "^4.0.2"
},
"devDependencies": {
Expand Down

0 comments on commit ebdf9e4

Please sign in to comment.