fix(http): stop labeling resource-endpoint 400s as credential errors - #79
Conversation
HttpClient.handleResponse() threw HaloPsaAuthenticationError with the message "Bad request - invalid credentials or parameters" for any 400 response that wasn't in the recognized validation-error shape, regardless of the actual endpoint. That's misleading: skipAuth is never true outside this file (the OAuth token endpoint is fetched directly by AuthManager, not through HttpClient), so every 400 that reaches this branch is from an authenticated resource call, where a bad/expired Bearer token already fails as 401, not 400. A 400 here is always the request body itself being rejected. We hit this via halopsa-mcp: a POST /Actions call missing a server-required field (outcome isn't marked required in ActionCreateData) came back as a plain 400, surfaced to the caller as an "invalid credentials" error, and was read as an API-application permissions problem — sending the customer down the wrong path entirely. Add HaloPsaBadRequestError for this case and use it instead. The message now names the endpoint and says nothing about credentials. HaloPsaAuthenticationError keeps its 401 role plus the token endpoint's own legitimate 400 (thrown separately by AuthManager, unaffected by this change). Fixes #78 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JgXg1NhHo6DvvAqoPowppi
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe HTTP client now classifies non-validation 400 responses from resource endpoints as ChangesResource 400 error handling
Estimated code review effort: 2 (Simple) | ~15 minutes Merge Risk: ⚪ Minimal · up to Resource-endpoint 400 responses now use a neutral bad-request error while validation and authentication handling remain distinct. The updated behavior and regression coverage are ready to merge. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Summary
POST /Actions) was thrown asHaloPsaAuthenticationErrorwith the message"Bad request - invalid credentials or parameters", even thoughskipAuthis never true outsideHttpClient(the OAuth token endpoint is fetched directly byAuthManager, never throughHttpClient), so every 400 reaching that branch is from an already-authenticated resource call — a bad token fails as 401, not 400.HaloPsaBadRequestErrorfor this case; the message now names the endpoint and says nothing about credentials.HaloPsaAuthenticationErrorkeeps its 401 role plus the token endpoint's own legitimate 400 (unaffected — that's thrown separately inauth.ts).halopsa-mcp: aPOST /Actionscall missingoutcome(not marked required inActionCreateData, though HaloPSA's server apparently wants it) surfaced as an "invalid credentials" error and sent a customer down a permissions-troubleshooting path for a plain payload validation issue.Test plan
HaloPsaBadRequestError, notHaloPsaAuthenticationError, message has no "credentials" wording; a validation-shaped 400 still →HaloPsaValidationError(was previously untested)npm test— 271/271 passingnpm run lint— cleannpm run build— clean🤖 Generated with Claude Code
https://claude.ai/code/session_01JgXg1NhHo6DvvAqoPowppi
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit
Bug Fixes
New Features
HaloPsaBadRequestErrorfor unrecognized or malformed resource-request responses, including relevant request details.