Uploaded image for project: 'Bitbucket Data Center'
  1. Bitbucket Data Center
  2. BSERV-20045

REST API - Response code 200 when searching for a file on an empty repository

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Low Low
    • None
    • 9.6.0
    • API - REST
    • None

      Issue Summary

      When using the REST API Get file content endpoint to search for a file on a repository that is empty, the response code is 200 while it should be 404, just like what happens when searching for an unexisting file against a non-empty repository (which returns a 404).

      Steps to Reproduce

      1. Create an empty repository and keep it empty
      2. Use the REST API Get file content endpoint to search for a file on that repository. 
      3. Notice that the HTTP response code will be 200

      Expected Results

      The response code should be 404 because the repository is empty and the file searched for can't be found.

      Actual Results

      The response code is 200 and the JSON response is empty:

      fkraemer@KD22HQ4RXH repositories % curl -k -v -u fkraemer -X GET -H 'Accept: application/json;charset=UTF-8' https://linux-95656.prod.atl-cd.net/bitbucket/rest/api/latest/projects/MPRA/repos/my-repo---rest-api/browse/wrongfile.txt
      Enter host password for user 'fkraemer':
      .
      .
      .
      * Request completely sent off
      < HTTP/2 200 
      < cache-control: no-cache, no-transform
      < content-type: application/json;charset=UTF-8
      < date: Fri, 04 Apr 2025 19:35:01 GMT
      < set-cookie: _3a585=c56b40073fafd059; Path=/
      < vary: X-AUSERNAME
      < vary: X-AUSERID
      < vary: Cookie
      < x-arequestid: @10OXPV5x1175x15016x0
      < x-auserid: 103
      < x-ausername: fkraemer
      < x-content-type-options: nosniff
      < content-length: 226
      < 
      * Connection #0 to host linux-95656.prod.atl-cd.net left intact
      {"path":{"components":["wrongfile.txt"],"parent":"","name":"wrongfile.txt","extension":"txt","toString":"wrongfile.txt"},"revision":"refs/heads/master","children":{"size":0,"limit":500,"isLastPage":true,"values":[],"start":0}} 

      For comparison, when searching for an unexisting file against a non-empty repository, the response code is 404:

      fkraemer@KD22HQ4RXH repositories % curl -k -v -u fkraemer -X GET -H 'Accept: application/json;charset=UTF-8' https://linux-95656.prod.atl-cd.net/bitbucket/rest/api/latest/projects/MPWI/repos/my-repo---web-interface/browse/wrongfile.txt
      .
      .
      .
      * Request completely sent off
      < HTTP/2 404 
      < cache-control: no-cache, no-transform
      < content-type: application/json;charset=UTF-8
      < date: Fri, 04 Apr 2025 19:34:01 GMT
      < set-cookie: _3a585=c56b40073fafd059; Path=/
      < vary: X-AUSERNAME
      < vary: X-AUSERID
      < vary: Cookie
      < x-arequestid: @10OXPV5x1174x15004x0
      < x-auserid: 103
      < x-ausername: fkraemer
      < x-content-type-options: nosniff
      < content-length: 170
      < 
      * Connection #0 to host linux-95656.prod.atl-cd.net left intact
      {"errors":[{"message":"The path \"wrongfile.txt\" does not exist at revision \"refs/heads/main\"","exceptionName":"com.atlassian.bitbucket.content.NoSuchPathException"}]}

      Workaround

      Currently, there is no known workaround for this behavior. A workaround will be added here when available

              Unassigned Unassigned
              fkraemer Felipe Kraemer
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated: