Q: Laravel json response error with status code Hello guys please I'm working on a project where if a clients account is suspended he won't be able to perform any transaction. I've gotten the success and error response but I want the error message to show in two different ways. First if the users account is suspended and the other if the amount inputed by the user is greater than his balance.
Here's my code
In my controller
     public function posttransfer(Request $request)
     {
        // dd($request);

        $suspend = AccountStatus::where('status','SUSPENDED')->first();
        if ($suspend->id == Auth::user()->status_id) {
            return error()->json(['error' => true] , 201);
        }

        $user = Auth::user()->id;
        $sender = User::where('id' , $user)->first();
        $balance = $sender->total_balance;
        $avbalance = $sender->available_balance;
        if ($request->transfer_amount > $balance) {
            return error()->json(['error' => true]);
        }
        $transfer = new Transfer;
        $transfer->user_id = $user;
        $transfer->transfer_type = $request->transfer_type;
        $transfer->beneficiary_accname = $request->beneficiary_accname;
        $transfer->country = $request->country;
        $transfer->beneficiary_accno = $request->beneficiary_accno;
        $transfer->transfer_amount = $request->transfer_amount;
        $transfer->beneficiary_bank = $request->beneficiary_bank;
        $transfer->swift_code = $request->swift_code;
        $transfer->rounting_code = $request->rounting_code;
        $transfer->transfer_desc = $request->transfer_desc;
        $transfer->acctype_id = $request->acctype_id;
        $transfer->transfer_status = 'Pending';
        $transfer->save();

         $avtotal = $avbalance  - $transfer->transfer_amount;
         User::where('id' , $user)->update(['available_balance' => $avtotal]); 
         
         return response()->json(['success' => true]);

     }

And my ajax request in my blade
<script>

   let avbalance = {{Auth::user()->total_balance}};
   $('#transfer_amount').keyup(function () {
      if (this.value > avbalance) {
        Swal.fire({
         icon: 'error',
         title: 'Oops...',
         text: 'Amount Inputed exceeds your balance!',
       })
      }
   });

   $('#transfer').submit(function(e){
             e.preventDefault();
             e.stopImmediatePropagation();
              $('#modelId').modal('show');
             $.ajax({
               url: "{{route('dashboard.posttransfer')}}",
               type: "POST",
               data: $('#transfer').serialize(),
               error:function(error){
                 if (error.status == 201) {
                  alert(error.status);
                  $('#modelId').modal('hide');
                  $('#transfer')[0].reset();
                  $('#errormodal').modal('show');
                 } else {
                  $('#modelId').modal('hide');
                 Swal.fire({
                 icon: 'error',
                 title: 'Oops...',
                 text: 'Sorry You cannot transfer above your balance!',
                 });
                 }
               },
               success:function(response){
                  $('#modelId').modal('hide');
                   $('#transfer')[0].reset();
                   Swal.fire({
                  position: 'top-end',
                  icon: 'success',
                  title: 'Transfer Pending ...',
                  text: "Please Check Status to verify payment",
                  showConfirmButton: false,
                  timer: 2000
                }); 
                $("#table").load(" #table > *");                
               }
             });
          });
</script>

<!-- Modal -->
<div class="modal" id="modelId" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="modelTitleId" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-body">
        <div align="center">
          <br>
            <h5>Transfer Processing Please Wait</h5>
            <img src="{{asset('dasharea/img/processing.gif')}}" alt="processing-gif" width="70">
        </div>
      </div>
    </div>
  </div>
</div>


          <!--Error Modal -->
          <div class="modal fade" id="errormodal" tabindex="-1" role="dialog" aria-labelledby="modelTitleId" aria-hidden="true">
            <div class="modal-dialog" role="document">
              <div class="modal-content">
                <div class="modal-header">
                  <h5 class="modal-title"><span class="text-danger">Warning !</span></h5>
                  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                </div>
                <div class="modal-body">
                  <h6>Your account has been <b>SUSPENDED</b> therefore you can't perform any task on this account. Contact us here for more info :</h6>
                  <form action="{{route('contact.mail')}}" method="post">
                    @csrf
                <div class="form-group">
                    <label for="name" class="form-label">Name</label>
                    <input type="text" name="name" id="name" class="form-control" placeholder="Enter your name">
                </div>
                <div class="form-group">
                    <label for="email" class="form-label">Email</label>
                    <input type="email" name="email" class="form-control" id="email" placeholder="Enter Valid Email Address">
                </div>
                <div class="form-group">
                    <label for="subject" class="form-label">Subject</label>
                    <input type="text" name="subject" id="subject" class="form-control" placeholder="Enter Subject">
                </div>
                <div class="form-group">
                    <label for="message" class="form-label">Message</label>
                    <textarea name="msg" id="message" cols="30" rows="5" class="form-control"></textarea>
                </div>
                <div class="form-buttons-w">
                    <button type="submit" class="btn btn-primary">Send</button>
                </div>
            </form>
                </div>
              </div>
            </div>
          </div>

Please guys I seriously need help on this, the second error that I passed that's after checking if the users account is suspended keeps on showing even when I log into a users account where his account status is suspended. The success message doesn't have any problem its working well the only issue is this error response part. Thanks in advance.
