Skip to content

Instantly share code, notes, and snippets.

@bobbybouwmann
Created March 8, 2022 07:39
Show Gist options
  • Save bobbybouwmann/6c9cbb3f10f6e53efdd8f0b2327d57ec to your computer and use it in GitHub Desktop.
Save bobbybouwmann/6c9cbb3f10f6e53efdd8f0b2327d57ec to your computer and use it in GitHub Desktop.
Exceptions for Christoph
class ChangeEmailController extends Controller
{
public function index(Request $request)
{
try {
$this->commandBus->handle(new ChangeEmailCommand($subscriptionId, $request->input('email'));
} catch (UnableToSendEmailChangeRequestException $exception) {
return response()->json([
'reasonCode' => $exception->reasonCode
], Response::HTTP_UNPROCESSABLE_ENTITY);
} catch (InvalidArgumentException $exception) {
return $this->respondWithErrorCode('invalidEmail');
} catch (SameEmailException $exception) {
return $this->respondWithErrorCode('sameEmail');
}
return response()->json([], Response::HTTP_NO_CONTENT);
}
private function respondWithErrorCode(string $code)
{
return response()->json([
'reasonCode' => $code,
], Response::HTTP_BAD_REQUEST);
}
}
try {
$this->contractService->retention(
$contractId,
$portfolioGuid,
$duration,
$products
);
Result::success();
} catch (MissingProductException|InvalidPortfolioGuidException) {
return Result::failure([
"You didn't selected the correct products, please try again",
]);
} catch (ChangeInProgressException) {
return Result::failure([
"It's currently not possible to perform a retention, try it again later.',
]);
} catch (Exception $exception) {
\Sentry\captureException($exception);
return Result::failure([
'Unknown erorr occurred, try it later again',
]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment