API: Fixes return code when accessing non existent branch (#2922)

Accessing a non-existent repository branch via API returned a status code 200 and content `null`. Now a 404 error code is returned. Added a test to check the status code. See issue #2922.