Created
March 8, 2022 07:39
-
-
Save bobbybouwmann/6c9cbb3f10f6e53efdd8f0b2327d57ec to your computer and use it in GitHub Desktop.
Exceptions for Christoph
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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