goharbor / goharbor/harbor-cli
refactor: make HTTP error code parsing robust
- Dominant language
- Go
- Stars
- 163
- Forks
- 211
- Avg merge
- 1m
- Merged PRs (30d)
- 1
Description
## Problem
The `ParseHarborErrorCode` function in `pkg/utils/error.go` parses HTTP error codes using brittle string splitting that may fail silently on different error string formats returned by the Harbor API client.
## Proposed Solution
- Support multiple error string formats (e.g., `[GET /projects][404]` and `(status 404)`)
- Add a regex-based fallback parser
- Add unit tests to cover both formats
## Affected File
- `pkg/utils/error.go`
Contributor guide
Research direction
Start with ParseHarborErrorCode in pkg/utils/error.go and inspect its current string-splitting behavior. Add coverage for the [GET /projects][404] and (status 404) formats, including the regex fallback, then run the package’s unit tests. Done means both formats are parsed correctly without silent failures.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, cli
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100