nepse_client.exceptions
Custom exceptions for NEPSE Client.
This module provides a comprehensive exception hierarchy for handling various error scenarios when interacting with the NEPSE API.
Functions
|
Get appropriate exception class for HTTP status code. |
Exceptions
Raised when access token has expired (401 Unauthorized). |
|
Raised when server returns 502 Bad Gateway. |
|
Raised when client sends an invalid request (4xx errors). |
|
Raised when there's an issue with client configuration. |
|
Raised when connection to NEPSE server fails. |
|
Raised when requested data is not found. |
|
Base exception class for all NEPSE-related errors. |
|
Raised for general network or unexpected HTTP issues. |
|
Raised when API rate limit is exceeded (429 Too Many Requests). |
|
Generic server error for 5xx status codes. |
|
Raised when request times out. |
|
Raised when input validation fails before making API request. |
- exception nepse_client.exceptions.NepseError[source]
Bases:
ExceptionBase exception class for all NEPSE-related errors.
All custom exceptions in this library inherit from this class, allowing for easy catch-all error handling.
- message
Human-readable error description
- status_code
HTTP status code (if applicable)
- response_data
Raw response data from the API
- request_data
Original request data
- __init__(message, status_code=None, response_data=None, request_data=None)[source]
Initialize NepseError.
- Parameters:
message (
str) – Error descriptionstatus_code (
Optional[int]) – HTTP status coderesponse_data (
Optional[Any]) – Response from the APIrequest_data (
Optional[dict[str,Any]]) – Original request data
- exception nepse_client.exceptions.NepseClientError[source]
Bases:
NepseErrorRaised when client sends an invalid request (4xx errors).
This typically indicates: - Invalid parameters - Missing required fields - Malformed request data - Invalid company symbol
Example
>>> try: ... client.getCompanyDetails("INVALID") ... except NepseClientError as e: ... print(f"Invalid request: {e}")
- exception nepse_client.exceptions.NepseAuthenticationError[source]
Bases:
NepseErrorRaised when access token has expired (401 Unauthorized).
This exception is typically handled automatically by the client, which will refresh the token and retry the request.
Note
Users usually don’t need to handle this exception directly as the client manages token refresh automatically.
- exception nepse_client.exceptions.NepseBadGatewayError[source]
Bases:
NepseErrorRaised when server returns 502 Bad Gateway.
This typically indicates: - Server temporarily unavailable - Upstream server issues - Network problems between servers
Recommended action: Retry the request after a short delay.
- exception nepse_client.exceptions.NepseServerError[source]
Bases:
NepseErrorGeneric server error for 5xx status codes.
This indicates an error on the NEPSE server side. Common causes: - Internal server error (500) - Service unavailable (503) - Gateway timeout (504)
Recommended action: Retry with exponential backoff or contact support.
- exception nepse_client.exceptions.NepseNetworkError[source]
Bases:
NepseErrorRaised for general network or unexpected HTTP issues.
This covers: - Connection timeouts - DNS resolution failures - SSL/TLS errors - Unexpected response formats - Network interruptions
Recommended action: Check network connectivity and retry.
- exception nepse_client.exceptions.NepseValidationError[source]
Bases:
NepseErrorRaised when input validation fails before making API request.
This is raised for client-side validation errors such as: - Invalid date formats - Out of range values - Missing required parameters - Invalid data types
Example
>>> try: ... client.getCompanyPriceVolumeHistory("NABIL", start_date="invalid") ... except NepseValidationError as e: ... print(f"Validation error: {e}")
- exception nepse_client.exceptions.NepseRateLimitError[source]
Bases:
NepseErrorRaised when API rate limit is exceeded (429 Too Many Requests).
- retry_after
Seconds to wait before retrying (if provided by server)
- exception nepse_client.exceptions.NepseDataNotFoundError[source]
Bases:
NepseErrorRaised when requested data is not found.
This is used when: - Company symbol doesn’t exist - No data available for requested date - Empty result sets
Example
>>> try: ... client.getFloorSheetOf("INVALID", "2024-01-01") ... except NepseDataNotFoundError as e: ... print(f"Data not found: {e}")
- exception nepse_client.exceptions.NepseTimeoutError[source]
Bases:
NepseErrorRaised when request times out.
This occurs when the server doesn’t respond within the specified timeout period.
- timeout
Timeout value in seconds
- exception nepse_client.exceptions.NepseConnectionError[source]
Bases:
NepseErrorRaised when connection to NEPSE server fails.
This is different from NepseNetworkError as it specifically indicates inability to establish a connection.
- exception nepse_client.exceptions.NepseConfigurationError[source]
Bases:
NepseErrorRaised when there’s an issue with client configuration.
This includes: - Missing required configuration files - Invalid configuration values - Corrupted data files
- nepse_client.exceptions.get_exception_for_status(status_code, message, response_data=None)[source]
Get appropriate exception class for HTTP status code.
- Parameters:
status_code (
int) – HTTP status codemessage (
str) – Error messageresponse_data (
Optional[Any]) – Response data from API
- Return type:
- Returns:
Appropriate exception instance