Skip to content

Conversation

jranaskit
Copy link
Collaborator

@jranaskit jranaskit commented Jul 19, 2025

[SK-1851] Update Error Handling for Python SDK

This PR is implemented to update error handling in the SDK methods. Compared to earlier version where we used to raise only error messages as part of the exceptions, here we are providing customer with an error response that conrains GRPC error codes, HTTP error codes and error details.

The Error returned by this change would be displayed as below example,

Example 1:
ScalekitServerException - Inheriting ScalekitException

- grpc_status (<StatusCode.INVALID_ARGUMENT: (3, 'invalid argument')>)
- http_status (<HTTPStatus.BAD_REQUEST: 400>)
- err_details (['Validation error', 'user.email: value must be a valid email address'])
- error_code 'INVALID_ARGUMENT'
_- message 'Validation error'

scalekit.common.exceptions.ScalekitBadRequestException: 
========================================
Error Code: INVALID_ARGUMENT
GRPC: (INVALID_ARGUMENT: (3, 'invalid argument'))
HTTP: (BAD_REQUEST: 400)
Error Details:
Validation error: [
error_code: "INVALID_ARGUMENT"
validation_error_info {
  field_violations {
    field: "user.email"
    description: "value must be a valid email address"
    constraint: "string.email"
  }
}
]
========================================

Copy link

Copy link
Contributor

@hrishikesh-p hrishikesh-p left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hrishikesh-p hrishikesh-p requested a review from Copilot July 25, 2025 14:39
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modernizes error handling in the Scalekit Python SDK by replacing generic exceptions with structured error responses that include GRPC error codes, HTTP status codes, and detailed error information. The changes provide developers with more comprehensive error context to better handle and debug API failures.

Key changes:

  • Replaced generic Exception instances with structured ScalekitException classes
  • Added mapping between GRPC and HTTP status codes for consistent error handling
  • Introduced specific exception types for different error scenarios (authentication, validation, server errors)

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.

File Description
scalekit/common/exceptions.py New exception hierarchy with structured error handling and status code mappings
scalekit/core.py Updated to use new exception classes instead of generic exceptions
scalekit/client.py Added specific token validation exception handling and moved webhook error class
Comments suppressed due to low confidence (3)

scalekit/common/exceptions.py:88

  • [nitpick] The method error_code should be a property to maintain consistency with other getters in the class like http_status and err_details. It should be decorated with @property.
    def error_code(self):

scalekit/common/exceptions.py:118

  • [nitpick] The method error_code should be a property to maintain consistency with other getters in the class like http_status and err_details. It should be decorated with @property.
    def error_code(self):

scalekit/common/exceptions.py:216

  • [nitpick] The method error_code should be a property to maintain consistency with other getters in the class like http_status and err_details. It should be decorated with @property.
    def error_code(self):

@dhawani
Copy link

dhawani commented Jul 28, 2025

bugbot run

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bugbot free trial expires on August 11, 2025
Learn more in the Cursor dashboard.

Copy link
Contributor

@hrishikesh-p hrishikesh-p left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jranaskit jranaskit merged commit 9fb9c7d into main Jul 30, 2025
2 checks 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.

3 participants