mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 03:12:54 +03:00
a958a66c4c
- PostsController orderBy function sorts posts with isNew to the top, otherwise their undefined dates fail to compare - also catch when `updated_at` is undefined, happens when model is being written with results from the server - catch objects of type Error in validation engine, helps catching client errors - join server errors with BR tag in ajax util - add `emberBuild` task to `grunt test-functional` - add a test helper, `thenTransitionAndWaitForScreenLoad`, to test transitioning to major parts of the app - add a test that transitions from Content to the Editor, and back to Content
44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
/* global ic */
|
|
|
|
var ajax = window.ajax = function () {
|
|
return ic.ajax.request.apply(null, arguments);
|
|
};
|
|
|
|
// Used in API request fail handlers to parse a standard api error
|
|
// response json for the message to display
|
|
var getRequestErrorMessage = function (request) {
|
|
var message,
|
|
msgDetail;
|
|
|
|
// Can't really continue without a request
|
|
if (!request) {
|
|
return null;
|
|
}
|
|
|
|
// Seems like a sensible default
|
|
message = request.statusText;
|
|
|
|
// If a non 200 response
|
|
if (request.status !== 200) {
|
|
try {
|
|
// Try to parse out the error, or default to 'Unknown'
|
|
if (request.responseJSON.errors && Ember.isArray(request.responseJSON.errors)) {
|
|
|
|
message = request.responseJSON.errors.map(function (errorItem) {
|
|
return errorItem.message;
|
|
}).join('<br />');
|
|
} else {
|
|
message = request.responseJSON.error || 'Unknown Error';
|
|
}
|
|
} catch (e) {
|
|
msgDetail = request.status ? request.status + ' - ' + request.statusText : 'Server was not available';
|
|
message = 'The server returned an error (' + msgDetail + ').';
|
|
}
|
|
}
|
|
|
|
return message;
|
|
};
|
|
|
|
export { getRequestErrorMessage, ajax };
|
|
export default ajax;
|