$err->getMessage())); } } /** * Creates and returns a Result object. * * @param string $resultType The type of result to send back to the client. * @param array $result The result object to send back to the client. * * @return Model\Result */ public static function createResult ( string $resultType, array $result ): Model\Result { try { return new Model\Result($resultType, $result); } catch (\Exception $err) { return new Model\Result("ERROR", array($err->getMessage())); } } /** * Obtain the error result based on the exception that was thrown. * * @param \Exception $err the error that was thrown. * * @return Model\Result */ public static function errorResult (\Exception $err): Model\Result { $errorType = ""; // Juggle error: objective is to sort error type try { throw $err; } catch (\PDOException $e) { $errorType = "DATABASE_ERROR"; } catch (\Exception $e) { $errorType = "ERROR"; } return new Model\Result($errorType, array("error" => $err->getMessage())); } }