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) {
|
).then(function(data) {
|
||||||
return data;
|
return data;
|
||||||
}, function(xhr) {
|
}, function(xhr) {
|
||||||
if (!xhr.responseJSON) {
|
return xhr.responseJSON;
|
||||||
return {
|
|
||||||
errors: [{ error: 'undefined', message: "An unknown error occurred." }]
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return xhr.responseJSON;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// clear options
|
// clear options
|
||||||
|
@ -15,11 +15,20 @@ abstract class Endpoint {
|
|||||||
function errorResponse(
|
function errorResponse(
|
||||||
$errors = array(), $meta = array(), $status = Response::STATUS_NOT_FOUND
|
$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);
|
return new ErrorResponse($errors, $meta, $status);
|
||||||
}
|
}
|
||||||
|
|
||||||
function badRequest($errors = array(), $meta = array()) {
|
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);
|
return new ErrorResponse($errors, $meta, Response::STATUS_BAD_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -36,6 +36,7 @@ class SettingsTest extends MailPoetTest {
|
|||||||
$router = new Settings();
|
$router = new Settings();
|
||||||
|
|
||||||
$response = $router->set(/* missing data */);
|
$response = $router->set(/* missing data */);
|
||||||
|
expect($response->errors[0]['error'])->equals('bad_request');
|
||||||
expect($response->status)->equals(Response::STATUS_BAD_REQUEST);
|
expect($response->status)->equals(Response::STATUS_BAD_REQUEST);
|
||||||
|
|
||||||
$response = $router->set($new_settings);
|
$response = $router->set($new_settings);
|
||||||
|
@ -110,7 +110,7 @@
|
|||||||
$('.mailpoet_page_preview').on('click', function() {
|
$('.mailpoet_page_preview').on('click', function() {
|
||||||
var selection = $(this).siblings('.mailpoet_page_selection');
|
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('href', $(selection).find('option[value="'+$(selection).val()+'"]').data('preview-url'));
|
||||||
$(this).attr('target', '_blank');
|
$(this).attr('target', '_blank');
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user