Skip to content

Conversation

@alukach
Copy link
Contributor

@alukach alukach commented May 29, 2025

What I'm changing

I noticed that when an ApiClientError is thrown (e.g. the source API returns a 401 for a private repository), the proxy throws a 502 gateway error. This obfuscates the underlying error. Instead, we should pass that error through from the proxy.

Running into this error

I have a disabled repo at https://source.coop/alukach/test-repo. The API returns a 401 when I attempt to access it: https://source.coop/api/v1/repositories/alukach/test-repo
However, the data proxy currently returns a 502 because the 401:

▶ curl https://data.source.coop/alukach/test-repo/xyz --verbose
// ...
< HTTP/2 502 
< date: Thu, 29 May 2025 19:42:09 GMT
< content-length: 203
< x-version: 0.1.28
< access-control-allow-credentials: true
< vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
< 
* Connection #0 to host data.source.coop left intact
Internal Server Error: api threw a client error (url https://source.coop/api/v1/repositories/alukach/test-repo, status 401, message {"code":401,"message":"You are not authorized to perform this action"})%       

How I did it

Updated the ResponseError implementation for BackendError to correctly pass through client error status codes from ApiClientError, ensuring that the appropriate status code is returned in the response.

How to test it

PR Checklist

  • This PR has no breaking changes.
  • I have updated or added new tests to cover the changes in this PR.
  • This PR affects the Source Cooperative Frontend & API,
    and I have opened issue/PR #XXX to track the change.

Related Issues

…andling

Updated the ResponseError implementation for BackendError to correctly pass through client error status codes from ApiClientError, ensuring that the appropriate status code is returned in the response.
@alukach alukach marked this pull request as ready for review May 29, 2025 19:45
@alukach alukach requested a review from gadomski May 29, 2025 20:02
@alukach alukach merged commit fe383dd into main May 29, 2025
4 checks passed
@alukach alukach deleted the fix/pass-client-error-status-code branch May 29, 2025 21:25
alukach pushed a commit that referenced this pull request May 29, 2025
🤖 I have created a release *beep* *boop*
---


##
[0.1.29](v0.1.28...v0.1.29)
(2025-05-29)


### Bug Fixes

* **errors:** pass through client error status codes
([#77](#77))
([fe383dd](fe383dd))
* **logging:** only log server errors, remove unnecessary details from
logs
([#75](#75))
([496373c](496373c))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: source-coop-release[bot] <187876225+source-coop-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants