Invalid API endpoint exception improvement

MAILPOET-6022
This commit is contained in:
Oluwaseun Olorunsola
2024-05-14 10:42:44 +01:00
committed by Aschepikov
parent a7df6b496f
commit 95e595de42
2 changed files with 11 additions and 3 deletions

View File

@@ -269,10 +269,17 @@ class API {
}
public function createErrorResponse($errorType, $errorMessage, $responseStatus) {
$errorResponse = new ErrorResponse(
[
$errorMessages = [
$errorType => $errorMessage,
],
];
if ($errorType === Error::BAD_REQUEST) {
$mpReinstallErrorMessage = __('The plugin has encountered an unexpected error. Please reload the page. If that does not help, re-install the MailPoet Plugin. See: https://kb.mailpoet.com/article/258-re-installing-updating-the-plugin-via-ftp', 'mailpoet');
$errorMessages[Error::REINSTALL_PLUGIN] = $mpReinstallErrorMessage; // not all places on the frontend accept html for an error message. we want this to be backwards compatible
}
$errorResponse = new ErrorResponse(
$errorMessages,
[],
$responseStatus
);

View File

@@ -8,6 +8,7 @@ final class Error {
const UNAUTHORIZED = 'unauthorized';
const FORBIDDEN = 'forbidden';
const NOT_FOUND = 'not_found';
const REINSTALL_PLUGIN = 'reinstall_plugin';
private function __construct() {