Repository navigation
fix(api): map ClickUp API errors to typed, user-friendly errors - #64
Merged
Merged
Conversation
Client.handleError was a passthrough, so users saw raw SDK strings such as "GET https://api.clickup.com/api/v2/task/x: 401 Team not authorized OAUTH_027". It now converts the SDK's ErrorResponse, RateLimitError and AbuseRateLimitError into *errors.APIError, which carries a category sentinel (ErrNotAuthenticated, ErrPermissionDenied, ErrNotFound, ErrRateLimited, ErrServer, ErrInvalidInput), resource context parsed from the request path, and the HTTP status/ECODE/ClickUp message in a trailing parenthetical. The original SDK error stays in the unwrap chain. ClickUp answers 401 OAUTH_027 "Team not authorized" for IDs the token cannot see, including typos, so that case reads as not found rather than telling the user to log in again. internal/errors drops the never-called UserError and HandleHTTPError and the unused ErrConfigNotFound in favour of the single APIError type. Part of #27 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Part of #27 (part 1 only: typed error mapping in
api.Client.handleError. Migrating commands fromRun+os.ExittoRunEwill be a separate follow-up).Client.handleErrorwas a passthrough, andinternal/errors(UserError,HandleHTTPError) was never called, so users got raw SDK strings.handleErrornow turns the SDK's*clickup.ErrorResponse,*clickup.RateLimitErrorand*clickup.AbuseRateLimitErrorinto a single*errors.APIErrorwith:errors.Is:ErrNotAuthenticated(401),ErrPermissionDenied(403),ErrNotFound(404),ErrRateLimited(429),ErrServer(5xx),ErrInvalidInput(400)task/abc→task "abc",team/123→workspace "123")ECODEanderrtext kept in a trailing parentheticalerrors.As(err, &*clickup.ErrorResponse)still worksAlready-typed errors are returned unchanged. Network and context errors pass through untouched.
Before / after (
cu task view bogus-id, checked live, read-only):Other mappings (from the httptest suite):
Notes:
cu auth loginwould be wrong here, so this case is classified asErrNotFound. Other 401s (OAUTH_017 missing header, OAUTH_025 invalid token, and so on) map toErrNotAuthenticated.errorfield added in feat(output): honour -o json/yaml/csv across every command #52 stays clean.internal/errors: removed the never-calledUserError,HandleHTTPErrorand oldAPIError/NewAPIError, plus the unusedErrConfigNotFound.IsRetryableand the sentinels used byinternal/authandretry.gostay as they were.internal/apialready went throughhandleError(16 inclient.go, pluscustomfields.go,status.go,archive.goandteamtasks.go). None were missing.Tests:
internal/api/errors_test.goruns a status-code table through a realClientagainst httptest. It also coversRateLimitErrorplus the SDK's synthetic-403 short-circuit, resource context across several endpoints using the production/api/v2/base path, and the passthrough cases (network, context, already typed).Checklist
./scripts/ci.shpasses locally (orgo test -race ./...at minimum).go test -race ./...,go vet ./...and gosec v2.28.0 are clean. The script's local errcheck step reports existing findings ininternal/cmd, none in files this PR touches.feat:,fix:,docs:,chore:,ci:,test:)cu docs markdown --dir docs/site/commands). N/A, no help text changed.🤖 Generated with Claude Code