Skip to content

Commit

Permalink
Better server error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
gpoitch committed Sep 13, 2014
1 parent 8eeeb50 commit aca842a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 32 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ContentKit-Editor [![Build Status](https://travis-ci.org/ContentKit/content-kit-editor.svg?branch=master)](https://travis-ci.org/ContentKit/content-kit-editor)

A modern, minimalist WYSIWYG editor. (**[Demo](https://rawgit.com/ContentKit/content-kit-editor/master/demo/index.html)**)
A modern, minimalist WYSIWYG editor.

![screenshot]
(https://rawgit.com/ContentKit/content-kit-editor/master/screenshot.png)
Expand All @@ -13,8 +13,7 @@ A modern, minimalist WYSIWYG editor. (**[Demo](https://rawgit.com/ContentKit/co

## Playing
1. Start the server: `npm start`
2. Navigate to the demo at (http://localhost:5000)
```
2. Navigate to the demo at [http://localhost:5000]

## Testing
`gulp test`
Expand Down
8 changes: 4 additions & 4 deletions server/config.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"aws" : {
"accessKeyId" : null,
"secretAccessKey" : null,
"accessKeyId" : "XXXXXX",
"secretAccessKey" : "XXXXXX",
"region" : "us-east-1"
},
"s3" : {
"bucketName" : null,
"bucketName" : "XXXXXX",
"maxFileSize" : 5000000
},
"embedlyKey" : null,
"embedlyKey" : "XXXXXX",
"cors" : {
"origin" : "*"
}
Expand Down
20 changes: 8 additions & 12 deletions server/services/embed.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
var embedly = require('embedly');
var util = require('util');

var EMBEDLY_KEY = 'XXXXXX';
var config = require('../config');

module.exports = function(req, res) {

new embedly({key: EMBEDLY_KEY}, function(err, api) {
if (!!err) {
console.error('Error creating Embedly api');
console.error(err.stack, api);
new embedly({key: config.embedlyKey}, function(err, api) {
if (err) {
console.log(err);
return res.status(500).json(err);
}

Expand All @@ -18,14 +16,12 @@ module.exports = function(req, res) {
}

api.oembed({url: url}, function(err, objs) {
if (!!err) {
console.error(err.stack, objs);
return res.status(500).json(err);
if (err) {
console.log(err, objs);
var message = JSON.parse(objs).error_message;
return res.status(500).json(message);
}

if (objs[0].error_message) {
return res.status(500).json(objs[0].error_message);
}
console.log(util.inspect(objs[0]));
res.json(objs[0]);
});
Expand Down
15 changes: 4 additions & 11 deletions server/services/s3-uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function readFileStream(req, res) {
busboy.on('file', function(fieldname, stream, filename, encoding, mimeType) {
if (!filename) {
stream.resume();
return res.json(500, { message: 'invalid file', status: 500 });
return res.status(500).json({ message: 'invalid file', status: 500 });
}
req.files = req.files || {};

Expand All @@ -27,12 +27,12 @@ function readFileStream(req, res) {
});

stream.on('error', function(error) {
return res.json(500, { message: 'error reading file', status: 500 });
return res.status(500).json({ message: 'error reading file', status: 500 });
});

stream.on('end', function() {
if (this.truncated) {
return res.json(500, { message: 'max file size is ' + maxFileSize + ' bytes', status: 500 });
return res.status(500).json({ message: 'max file size is ' + maxFileSize + ' bytes', status: 500 });
}
var finalBuffer = Buffer.concat(this.chunks);
var file = req.files[fieldname] = {
Expand Down Expand Up @@ -68,17 +68,10 @@ function putFileBufferToS3(file, res) {

var request = s3.putObject(params, function(error, data) {
if (error) {
return res.json(500, { message: 'error uploading to S3', status: 500 });
return res.status(500).json({ message: error.message || 'Error uploading to S3', status: 500 });
}
res.json({ url: 'https://s3.amazonaws.com/' + uploadBucket + '/' + key });
});

// Can we send this to the client?
/*
request.on('httpUploadProgress', function (progress) {
console.log('Uploaded', progress.loaded, 'of', progress.total, 'bytes');
});
*/
}

module.exports = readFileStream;
2 changes: 1 addition & 1 deletion src/js/content-kit-editor/commands/oembed.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ OEmbedCommand.prototype.exec = function(url) {
if (error.target && error.target.status === 0) {
errorMsg = 'Error: could not connect to embed service.';
} else if (typeof error !== 'string') {
errorMsg = 'Error: embeds are broken :/';
errorMsg = 'Error: unexpected embed error.';
}
new Message().show(errorMsg);
embedIntent.show();
Expand Down
2 changes: 1 addition & 1 deletion src/js/content-kit-editor/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var defaults = {
new SubheadingCommand()
],
embedCommands: [
new ImageCommand({ serviceUrl: '/images' }),
new ImageCommand({ serviceUrl: '/upload' }),
new OEmbedCommand({ serviceUrl: '/embed' })
],
autoTypingCommands: [
Expand Down

0 comments on commit aca842a

Please sign in to comment.