diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 7d7d19a..68b5f11 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -3,6 +3,7 @@ namespace App\Exceptions; use App\Traits\ApiResponser; +use GuzzleHttp\Exception\ClientException; use GuzzleHttp\Exception\ServerException; use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Auth\AuthenticationException; @@ -100,6 +101,18 @@ class Handler extends ExceptionHandler return $this->errorResponse($exception->getMessage(),Response::HTTP_INTERNAL_SERVER_ERROR); } + if ( $exception instanceof ClientException) + { + $message = $exception->getResponse()->getBody()->getContents(); + $error =json_decode($message) ; + $code = $exception->getCode(); + + if($error) + return $this->errorResponse($error->error,$code); + else + return $this->errorResponse($message,$code); + } + if( env('APP_DEBUG', false)) { return parent::render($request,$exception); diff --git a/app/Http/Controllers/CreditController.php b/app/Http/Controllers/CreditController.php index e005474..bea43bb 100644 --- a/app/Http/Controllers/CreditController.php +++ b/app/Http/Controllers/CreditController.php @@ -48,7 +48,7 @@ class CreditController extends Controller $this->validate($request,$rules); if($walletParrain->balance_princ < $request->montant) - return $this->errorResponse(trans('messages.princ_balance_inf_to_demand_amount') . 'modified',Response::HTTP_BAD_REQUEST); + return $this->errorResponse(trans('messages.princ_balance_inf_to_demand_amount'),Response::HTTP_BAD_REQUEST); $walletAgent->balance_princ += $request->montant; $walletParrain->balance_princ -= $request->montant; @@ -72,7 +72,7 @@ class CreditController extends Controller // }catch (\Exception $e){ // echo "Error: " . $e->getMessage(); // } - return $this->successResponse(trans('messages.succes_treated_demand')); + return $this->successResponse(trans('messages.success_treated_demand')); } public function cancelDemand($id_demand ,Twilio $twilio){ diff --git a/resources/lang/en/messages.php b/resources/lang/en/messages.php index 386bb50..de1df1f 100644 --- a/resources/lang/en/messages.php +++ b/resources/lang/en/messages.php @@ -3,7 +3,7 @@ return [ 'empty_com_balance' => 'Commission balance is empty', 'treated_demand' => 'Credit request already processed', 'canceled_demand' => 'Canceled credit request', - 'princ_balance_inf_to_demand_amount' => 'Your main balance is less than the amount of the request, do you want to change the amount?', + 'princ_balance_inf_to_demand_amount' => 'Your main balance is less than the amount of the request, do you want to change the amount ?', 'new_wallet_added' => 'New wallet added', - 'succes_treated_demand' => 'Request successfully processed' + 'success_treated_demand' => 'Request successfully processed' ]; diff --git a/resources/lang/fr/messages.php b/resources/lang/fr/messages.php index dc32b0c..9fed503 100644 --- a/resources/lang/fr/messages.php +++ b/resources/lang/fr/messages.php @@ -5,5 +5,5 @@ return [ 'canceled_demand' => 'Demande de credit annulée', 'princ_balance_inf_to_demand_amount' => 'Votre solde principal est inférieur au montant de la demande, voulez vous modifier le montant ?', 'new_wallet_added' => 'Nouveau wallet ajouté', - 'succes_treated_demand' => 'Demande traitée avec succès' + 'success_treated_demand' => 'Demande traitée avec succès' ];