feat: surface API 401 error message with login suggestion in portal generation#297
Open
MuhammadRafay1 wants to merge 3 commits into
Open
feat: surface API 401 error message with login suggestion in portal generation#297MuhammadRafay1 wants to merge 3 commits into
MuhammadRafay1 wants to merge 3 commits into
Conversation
…eneration Previously, running portal commands while logged out showed the generic "An unexpected error occurred" message because the SDK's typed 401 error (UnauthorizedResponseError) was not recognized by the axios-only handleServiceError. Handle ApiError with status 401 in generatePortal, extract the API's message, and pair it with a suggestion to run `apimatic auth login` or pass `--auth-key`. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Add the contribution workflow (branching, local debugging/packaging, README updates, CLI and Platform SDK release process, NPM tagging) as an AI skill file, with package-manager commands updated from npm to pnpm, and index it in CLAUDE.md and .ai/instructions.md. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
MuhammadRafay1
requested review from
Shield-Jaguar,
aliasghar98 and
saeedjamshaid
as code owners
July 14, 2026 11:52
MuhammadRafay1
force-pushed
the
error-message-enhancement
branch
from
July 15, 2026 11:45
0d32c05 to
adaa8ae
Compare
…rviceError Move the 401 message extraction out of generatePortal's catch and into handleServiceError, which now recognizes SDK ApiError statuses (401/404/500) alongside axios errors. This surfaces the API's 401 message + login hint for every SDK-based flow, not just portal generation, and removes the unreachable 401 branch inside the ProblemDetailsError block. Co-Authored-By: Claude Opus 4.8 (1M context) <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.



Problem
Running portal commands without a valid session (e.g.
apimatic portal servewhile logged out) showed the generic fallback:even though the API returns a clear reason (
{"message": "Authorization has been denied for this request."}). The SDK throws its typedUnauthorizedResponseErrorfor 401s, buthandleServiceErroronly recognizes axios errors, so the genericServerError.Changes
portal-service.ts: IngeneratePortal's catch, handleApiErrorwith status 401 — extract the API's message from the deserialized errorresultand return aServiceErrorthat pairs it with a suggested fix. All other errors continue to flow throughhandleServiceErrorunchanged (kept scoped on purpose; message handling differs per flow).service-error.ts: NewServiceError.unauthorized(apiMessage)factory (alongsidebadRequest/forbidden/notFound) that appends "runapimatic auth loginor provide a valid auth key using the--auth-keyflag" to the API's message.Result
■ Portal Generation failed.
■ Authorization has been denied for this request. Please
to log in, or provide a valid auth key using the --auth-key flag.
Testing
portal servewith an empty config dir (logged out) against the production API — enhanced message shown.auth statuswith an invalid stored key still prints "Invalid API key provided." (relies on theServiceError.UnAuthorizedsingleton identity check, which is preserved).pnpm test: 45 passing, lint clean.