Commit fe383dd
authored
fix(errors): pass through client error status codes (#77)
## 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.
<details>
<summary>Running into this error</summary>
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`:
```sh
▶ 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"})%
```
</details>
## 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.
<!-- Discuss the implementation strategy and considerations made -->
## How to test it
## PR Checklist
- [x] This PR has **no** breaking changes.
- [x] I have updated or added new tests to cover the changes in this PR.
- [ ] This PR affects the [Source Cooperative Frontend &
API](https://github.com/source-cooperative/source.coop),
and I have opened issue/PR #XXX to track the change.
## Related Issues
<!-- Reference any existing related GitHub Issues -->1 parent 496373c commit fe383dd
1 file changed
+26
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
101 | 106 | | |
102 | 107 | | |
103 | 108 | | |
| |||
114 | 119 | | |
115 | 120 | | |
116 | 121 | | |
117 | | - | |
118 | 122 | | |
119 | 123 | | |
120 | 124 | | |
| |||
508 | 512 | | |
509 | 513 | | |
510 | 514 | | |
511 | | - | |
| 515 | + | |
512 | 516 | | |
513 | 517 | | |
514 | 518 | | |
515 | 519 | | |
516 | 520 | | |
517 | 521 | | |
518 | 522 | | |
519 | | - | |
520 | | - | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
521 | 543 | | |
522 | 544 | | |
523 | 545 | | |
| |||
0 commit comments