mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-14 09:52:09 +03:00
12e6b09943
closes #2414 - Add PostsController with loadNextPage action - Collect and store pagination info from PostsRoute into PostsController - Use `store.filter` on PostsRoute model hook to auto-update posts list template as post models are added to the store - Add content list view and use it to check for scroll event - Make PostRoute only load a post that's already in the store, until we figure how to load multiple pages on refresh - Add util function from clientold that concats error messages from server response
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('; ');
|
|
} 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;
|