Skip to content

fix: handle subscription plan errors without error_description field#4

Merged
terwey merged 4 commits intomainfrom
error/subscription_inactive
Nov 10, 2025
Merged

fix: handle subscription plan errors without error_description field#4
terwey merged 4 commits intomainfrom
error/subscription_inactive

Conversation

@terwey
Copy link
Copy Markdown
Collaborator

@terwey terwey commented Nov 10, 2025

Summary

Fixed a nil pointer dereference panic that occurred when the API returns error responses without an error_description field, particularly for subscription plan limitation errors.

Problem

When the 3Commas API returns a 429 error for subscription plan limitations, the response only contains the error field without the optional error_description field:

{
  "error": "The request type 'read' is not available with your current subscription plan. Please upgrade your plan to use this type of request."
}

The SDK's error handling code always attempted to dereference ErrorDescription, causing a panic:

runtime error: invalid memory address or nil pointer dereference

Changes

SDK Fix

  • Updated APIError.Error() method to check if ErrorDescription is nil before dereferencing
  • Falls back to the Error field when ErrorDescription is not present
  • Ensures robust error handling for all API error responses

OpenAPI Spec Enhancement

  • Updated RateLimitExceeded response description to clarify it covers both rate limiting and subscription plan limitations
  • Added examples for both traditional rate limit errors and subscription plan limitation errors

Testing

  • Added test case TestListBots/Subscription_not_active to verify the fix
  • Test validates proper error message formatting without panic

Impact

  • Bug Fix: Eliminates panic when handling subscription plan limitation errors
  • Better Error Messages: Users now see clear error messages for subscription issues
  • Improved Documentation: OpenAPI spec better reflects actual API behavior

@terwey terwey changed the title Error/subscription inactive fix: handle subscription plan errors without error_description field Nov 10, 2025
@terwey terwey marked this pull request as ready for review November 10, 2025 15:33
@terwey terwey merged commit c7c2e54 into main Nov 10, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant