0) throw ApiError::missingField($missing); // Try and create a new user, 400 if duplicate. try { Response::json(User::create($username, $email, $password)); } catch (Exception $err) { switch ($err->getMessage()) { case "NotFound": throw ApiError::failed("Failed to create user"); case "Duplicate": throw ApiError::duplicate("user"); default: throw $err; } } } public function patch(): void { // Fetch all required inputs. // Throw 400 error if a required one is missing. $code = Input::post("code"); if (empty($code)) throw ApiError::missingField(["code"]); // Try and confirm user, 404 if user not found. try { Response::json(User::confirm($code)); } catch (Exception $err) { switch ($err->getMessage()) { case "NotFound": throw ApiError::notFound("user"); default: throw $err; } } } }