Explorar el Código

added body to Exception Alerts

Piotr Labudda hace 9 años
padre
commit
916ce39a77
Se han modificado 2 ficheros con 15 adiciones y 4 borrados
  1. 4 0
      SE/se-lib/Response.php
  2. 11 4
      SE/se-lib/bootstrap.php

+ 4 - 0
SE/se-lib/Response.php

@@ -46,6 +46,7 @@ class Response {
 			$response['type'] = 'error';
 			$response['msg'] = $e->getMessage();
 			$response['code'] = "#" . $e->getCode() . "L" . $e->getLine();
+			$response['body'] = $e->getBody();
 			DBG::log($e);
 			Response::sendJsonExit($response);
 		} catch (AlertSuccessException $e) {
@@ -53,6 +54,7 @@ class Response {
 			$response['type'] = 'success';
 			$response['msg'] = $e->getMessage();
 			$response['code'] = "#" . $e->getCode() . "L" . $e->getLine();
+			$response['body'] = $e->getBody();
 			DBG::log($e);
 			Response::sendJsonExit($response);
 		} catch (AlertInfoException $e) {
@@ -60,6 +62,7 @@ class Response {
 			$response['type'] = 'info';
 			$response['msg'] = $e->getMessage();
 			$response['code'] = "#" . $e->getCode() . "L" . $e->getLine();
+			$response['body'] = $e->getBody();
 			DBG::log($e);
 			Response::sendJsonExit($response);
 		} catch (AlertWarningException $e) {
@@ -67,6 +70,7 @@ class Response {
 			$response['type'] = 'warning';
 			$response['msg'] = $e->getMessage();
 			$response['code'] = "#" . $e->getCode() . "L" . $e->getLine();
+			$response['body'] = $e->getBody();
 			DBG::log($e);
 			Response::sendJsonExit($response);
 		} catch (Exception $e) {

+ 11 - 4
SE/se-lib/bootstrap.php

@@ -7,10 +7,17 @@ define('APP_PATH_WWW', APP_PATH_ROOT);
 define('APP_PATH_CONFIG', APP_PATH_ROOT . DS . 'config');
 define('APP_PATH_SCHEMA', APP_PATH_ROOT . DS . 'schema');
 
-class AlertWarningException extends Exception {}
-class AlertDangerException extends Exception {}
-class AlertSuccessException extends Exception {}
-class AlertInfoException extends Exception {}
+// @usage: throw (new AlertSuccessException("Success"))->setBody([ 'id' => 123 ]);
+//         ... catch (AlertSuccessException $e) { $e->getBody(); ... }
+class AlertExceptionBase extends Exception {
+  public $_body;
+  public function setBody($body) { $this->_body = $body; return $this; }
+  public function getBody() { return $this->_body; }
+}
+class AlertWarningException extends AlertExceptionBase {}
+class AlertDangerException extends AlertExceptionBase {}
+class AlertSuccessException extends AlertExceptionBase {}
+class AlertInfoException extends AlertExceptionBase {}
 
 require_once APP_PATH_LIB . '/' . 'Lib.php';
 Lib::loadClass('DBG');