0) throw ApiError::missingField($missing); // Try and log in user. // Throw errors according to situation. try { Response::json(User::logIn($email, $password)); } catch (Exception $err) { switch ($err->getMessage()) { case "Failed": throw ApiError::failed("Login failed"); case "NotFound": throw ApiError::notFound("user"); case "Invalid": throw ApiError::notAllowed("Invalid username or password"); default: throw $err; } } } }