added default error messages to errorResponse and badRequest
This commit is contained in:
@ -60,13 +60,7 @@ define('ajax', ['mailpoet', 'jquery', 'underscore'], function(MailPoet, jQuery,
|
||||
).then(function(data) {
|
||||
return data;
|
||||
}, function(xhr) {
|
||||
if (!xhr.responseJSON) {
|
||||
return {
|
||||
errors: [{ error: 'undefined', message: "An unknown error occurred." }]
|
||||
};
|
||||
} else {
|
||||
return xhr.responseJSON;
|
||||
}
|
||||
});
|
||||
|
||||
// clear options
|
||||
|
@ -15,11 +15,20 @@ abstract class Endpoint {
|
||||
function errorResponse(
|
||||
$errors = array(), $meta = array(), $status = Response::STATUS_NOT_FOUND
|
||||
) {
|
||||
|
||||
if(empty($errors)) {
|
||||
$errors = array(
|
||||
'unknown' => __('An unknown error occurred.')
|
||||
);
|
||||
}
|
||||
return new ErrorResponse($errors, $meta, $status);
|
||||
}
|
||||
|
||||
function badRequest($errors = array(), $meta = array()) {
|
||||
if(empty($errors)) {
|
||||
$errors = array(
|
||||
'bad_request' => __('Invalid request parameters.')
|
||||
);
|
||||
}
|
||||
return new ErrorResponse($errors, $meta, Response::STATUS_BAD_REQUEST);
|
||||
}
|
||||
}
|
@ -36,6 +36,7 @@ class SettingsTest extends MailPoetTest {
|
||||
$router = new Settings();
|
||||
|
||||
$response = $router->set(/* missing data */);
|
||||
expect($response->errors[0]['error'])->equals('bad_request');
|
||||
expect($response->status)->equals(Response::STATUS_BAD_REQUEST);
|
||||
|
||||
$response = $router->set($new_settings);
|
||||
|
@ -110,7 +110,7 @@
|
||||
$('.mailpoet_page_preview').on('click', function() {
|
||||
var selection = $(this).siblings('.mailpoet_page_selection');
|
||||
|
||||
if(selection.length > 0) {
|
||||
if (selection.length > 0) {
|
||||
$(this).attr('href', $(selection).find('option[value="'+$(selection).val()+'"]').data('preview-url'));
|
||||
$(this).attr('target', '_blank');
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user