You either throw an exception or return a response. Not both
return response("There was a problem setting up your subscription, please contact us if the problem persists.", 400);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi Laravel community,
PLease could I get some advice for the following:
public function createPaymentIntent($id)
{
try {
$user = User::find($id);
return response($user->createSetupIntent(), 201);
} catch (Throwable $error) {
report($error);
return response(throw new UnprocessableEntityHttpException("There was a problem setting up your subscription, please contact us if the problem persists."), 400);
}
}
I am trying to start to integrate stripe, does the above make sense when handling errors??
Is there a better way to write this out? Even a link to some documentation or an article would be great of you do not have the time to give an example.
Many thanks
try {
$service->doSomething();
} catch (SomethingHorribleHappenedException) {
throw ValidationException::withMessages([
'error' => 'Something bad happened. Please try again later'
]);
}
An example 👆
Please or to participate in this conversation.