diff --git a/core/server/api/db.js b/core/server/api/db.js index 03c8abfd36..a31440e221 100644 --- a/core/server/api/db.js +++ b/core/server/api/db.js @@ -43,7 +43,7 @@ db = { * - If there is no path * - If the name doesn't have json in it */ - return when.reject(new errors.InternalServerError('Please select a .json file to import.')); + return when.reject(new errors.UnsupportedMediaTypeError('Please select a .json file to import.')); } return api.settings.read({key: 'databaseVersion', context: { internal: true }}).then(function (response) { diff --git a/core/server/api/index.js b/core/server/api/index.js index 8ae5353e70..90145559d2 100644 --- a/core/server/api/index.js +++ b/core/server/api/index.js @@ -208,6 +208,9 @@ http = function (apiMethod) { }).then(function addLocationHeader(header) { if (header) { res.set({'Location': header}); + // The location header indicates that a new object was created. + // In this case the status code should be 201 Created + res.status(201); } // Add Content-Disposition Header diff --git a/core/server/errors/index.js b/core/server/errors/index.js index 321b38893c..1801340c54 100644 --- a/core/server/errors/index.js +++ b/core/server/errors/index.js @@ -12,6 +12,7 @@ var _ = require('lodash'), RequestEntityTooLargeError = require('./requesttoolargeerror'), UnauthorizedError = require('./unauthorizederror'), ValidationError = require('./validationerror'), + UnsupportedMediaTypeError = require('./unsupportedmediaerror'), EmailError = require('./emailerror'), errors, @@ -258,4 +259,5 @@ module.exports.NoPermissionError = NoPermissionError; module.exports.UnauthorizedError = UnauthorizedError; module.exports.ValidationError = ValidationError; module.exports.RequestEntityTooLargeError = RequestEntityTooLargeError; +module.exports.UnsupportedMediaTypeError = UnsupportedMediaTypeError; module.exports.EmailError = EmailError; diff --git a/core/server/errors/unsupportedmediaerror.js b/core/server/errors/unsupportedmediaerror.js new file mode 100644 index 0000000000..6592ccc964 --- /dev/null +++ b/core/server/errors/unsupportedmediaerror.js @@ -0,0 +1,15 @@ +// # Unsupported Media Type +// Custom error class with status code and type prefilled. + +function UnsupportedMediaTypeError(message) { + this.message = message; + this.stack = new Error().stack; + this.code = 415; + this.type = this.name; +} + +UnsupportedMediaTypeError.prototype = Object.create(Error.prototype); +UnsupportedMediaTypeError.prototype.name = "UnsupportedMediaTypeError"; + + +module.exports = UnsupportedMediaTypeError; \ No newline at end of file diff --git a/core/test/functional/routes/api/notifications_test.js b/core/test/functional/routes/api/notifications_test.js index 5ae4b14bb5..d4fc894e5a 100644 --- a/core/test/functional/routes/api/notifications_test.js +++ b/core/test/functional/routes/api/notifications_test.js @@ -86,7 +86,7 @@ describe('Notifications API', function () { request.post(testUtils.API.getApiQuery('notifications/')) .set('X-CSRF-Token', csrfToken) .send(newNotification) - .expect(200) + .expect(201) .end(function (err, res) { if (err) { return done(err); @@ -119,7 +119,7 @@ describe('Notifications API', function () { request.post(testUtils.API.getApiQuery('notifications/')) .set('X-CSRF-Token', csrfToken) .send(newNotification) - .expect(200) + .expect(201) .end(function (err, res) { if (err) { return done(err); diff --git a/core/test/functional/routes/api/posts_test.js b/core/test/functional/routes/api/posts_test.js index cf0000d949..8686c62786 100644 --- a/core/test/functional/routes/api/posts_test.js +++ b/core/test/functional/routes/api/posts_test.js @@ -355,7 +355,7 @@ describe('Post API', function () { request.post(testUtils.API.getApiQuery('posts/?include=tags')) .set('X-CSRF-Token', csrfToken) .send(newPost) - .expect(200) + .expect(201) .end(function (err, res) { if (err) { return done(err); @@ -713,7 +713,7 @@ describe('Post API', function () { request.post(testUtils.API.getApiQuery('posts/')) .set('X-CSRF-Token', csrfToken) .send(newPost) - .expect(200) + .expect(201) .end(function (err ,res) { if (err) { return done(err);