mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Improve status codes
closes #2187 - added UnsupportedMediaTypeError (code: 415) - added status code 201 if a new object was created - Updated tests
This commit is contained in:
parent
11cf0ae125
commit
217e3ed7ad
6 changed files with 25 additions and 5 deletions
|
@ -43,7 +43,7 @@ db = {
|
||||||
* - If there is no path
|
* - If there is no path
|
||||||
* - If the name doesn't have json in it
|
* - 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) {
|
return api.settings.read({key: 'databaseVersion', context: { internal: true }}).then(function (response) {
|
||||||
|
|
|
@ -208,6 +208,9 @@ http = function (apiMethod) {
|
||||||
}).then(function addLocationHeader(header) {
|
}).then(function addLocationHeader(header) {
|
||||||
if (header) {
|
if (header) {
|
||||||
res.set({'Location': 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
|
// Add Content-Disposition Header
|
||||||
|
|
|
@ -12,6 +12,7 @@ var _ = require('lodash'),
|
||||||
RequestEntityTooLargeError = require('./requesttoolargeerror'),
|
RequestEntityTooLargeError = require('./requesttoolargeerror'),
|
||||||
UnauthorizedError = require('./unauthorizederror'),
|
UnauthorizedError = require('./unauthorizederror'),
|
||||||
ValidationError = require('./validationerror'),
|
ValidationError = require('./validationerror'),
|
||||||
|
UnsupportedMediaTypeError = require('./unsupportedmediaerror'),
|
||||||
EmailError = require('./emailerror'),
|
EmailError = require('./emailerror'),
|
||||||
errors,
|
errors,
|
||||||
|
|
||||||
|
@ -258,4 +259,5 @@ module.exports.NoPermissionError = NoPermissionError;
|
||||||
module.exports.UnauthorizedError = UnauthorizedError;
|
module.exports.UnauthorizedError = UnauthorizedError;
|
||||||
module.exports.ValidationError = ValidationError;
|
module.exports.ValidationError = ValidationError;
|
||||||
module.exports.RequestEntityTooLargeError = RequestEntityTooLargeError;
|
module.exports.RequestEntityTooLargeError = RequestEntityTooLargeError;
|
||||||
|
module.exports.UnsupportedMediaTypeError = UnsupportedMediaTypeError;
|
||||||
module.exports.EmailError = EmailError;
|
module.exports.EmailError = EmailError;
|
||||||
|
|
15
core/server/errors/unsupportedmediaerror.js
Normal file
15
core/server/errors/unsupportedmediaerror.js
Normal file
|
@ -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;
|
|
@ -86,7 +86,7 @@ describe('Notifications API', function () {
|
||||||
request.post(testUtils.API.getApiQuery('notifications/'))
|
request.post(testUtils.API.getApiQuery('notifications/'))
|
||||||
.set('X-CSRF-Token', csrfToken)
|
.set('X-CSRF-Token', csrfToken)
|
||||||
.send(newNotification)
|
.send(newNotification)
|
||||||
.expect(200)
|
.expect(201)
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return done(err);
|
return done(err);
|
||||||
|
@ -119,7 +119,7 @@ describe('Notifications API', function () {
|
||||||
request.post(testUtils.API.getApiQuery('notifications/'))
|
request.post(testUtils.API.getApiQuery('notifications/'))
|
||||||
.set('X-CSRF-Token', csrfToken)
|
.set('X-CSRF-Token', csrfToken)
|
||||||
.send(newNotification)
|
.send(newNotification)
|
||||||
.expect(200)
|
.expect(201)
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return done(err);
|
return done(err);
|
||||||
|
|
|
@ -355,7 +355,7 @@ describe('Post API', function () {
|
||||||
request.post(testUtils.API.getApiQuery('posts/?include=tags'))
|
request.post(testUtils.API.getApiQuery('posts/?include=tags'))
|
||||||
.set('X-CSRF-Token', csrfToken)
|
.set('X-CSRF-Token', csrfToken)
|
||||||
.send(newPost)
|
.send(newPost)
|
||||||
.expect(200)
|
.expect(201)
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return done(err);
|
return done(err);
|
||||||
|
@ -713,7 +713,7 @@ describe('Post API', function () {
|
||||||
request.post(testUtils.API.getApiQuery('posts/'))
|
request.post(testUtils.API.getApiQuery('posts/'))
|
||||||
.set('X-CSRF-Token', csrfToken)
|
.set('X-CSRF-Token', csrfToken)
|
||||||
.send(newPost)
|
.send(newPost)
|
||||||
.expect(200)
|
.expect(201)
|
||||||
.end(function (err ,res) {
|
.end(function (err ,res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return done(err);
|
return done(err);
|
||||||
|
|
Loading…
Add table
Reference in a new issue