title: How to clean up nil policy error which shows GET 500 (Internal Server Error)
body: <p>In the following case, some of the banks will not have branches.<br>
  Here is the controller.js code portion:</p>
  
  <pre class="lang-js prettyprint-override"><code>function loadBranch(bankId) {
    BankMetadataService.getBranch(bankId).then(function(resp) {
      $scope.branchId = resp.data.id;
      $scope.validbool = true;
    }, function() {
      // if a bank does not have a branch
      console.log("No existing branch for bank.");
      $scope.validbool = false;
    });
  }
  </code></pre>
  
  
  
  <p>here is the controller.rb code portion which looks for branches:</p>
  
  <pre><code>def bank_branch
    branch = BankMetadataBranch.where(bank_id: params[:bank]).first
    authorize branch, :show?
    render json: branch
  end
  </code></pre>
  
  <p>From UI when I select a bank that has no branch it shows the following error in inspect console:
  <code>GET http://localhost:.....?bank=1 500 (Internal Server Error)</code> with the <code>console.log</code> message. </p>
  
  <p>How can I clean up that <code>500(Internal Server Error)</code> message?</p>