goharbor / goharbor/harbor-cli

refactor: make HTTP error code parsing robust

Open
#1,039 1 comment 0 reactions 0 assignees View on GitHub
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.