getMessage()) { case "NotFound": throw ApiError::notFound("user"); default: throw $err; } } } public function patch($id): void { // Fetch all inputs. $username = Input::patch("username"); $password = Input::patch("password"); $email = Input::patch("email"); // Try and update user. // Throw errors according to situation. try { Response::json(User::getByID($id)->update($username, $password, $email)); } catch (Exception $err) { switch ($err->getMessage()) { case "NotFound": throw ApiError::notFound("user"); default: // Due to how the failed field is handled, it's ApiError is inside the models update throw $err; } } } public function patchSelf(): void { // Fetch all inputs. $token = Request::token(); $username = Input::patch("username"); $password = Input::patch("password"); $email = Input::patch("email"); // Try and update user. // Throw errors according to situation. try { Response::json(User::getByToken($token)->update($username, $password, $email)); } catch (Exception $err) { switch ($err->getMessage()) { case "NotFound": throw ApiError::notFound("user"); default: // Due to how the failed field is handled, it's ApiError is inside the models update throw $err; } } } public function delete($id): void { // Try to delete user, 404 if not found. try { Response::json(User::getByID($id)->delete()); } catch (Exception $err) { switch ($err->getMessage()) { case "NotFound": throw ApiError::notFound("user"); default: throw $err; } } } }