Skip to content

[fix]: Improve Error Handling in StockService #9

@0PrashantYadav0

Description

@0PrashantYadav0

Description

  • Detailed Description:
    The current error handling in StockService catches generic exceptions and returns a basic JSON error message. This can make it harder to diagnose the underlying issue.
  • How to Solve:
    1. Catch Specific Exceptions:
      Instead of catching a general Exception, catch more specific exceptions (e.g., RestClientException).
    2. Log Detailed Errors:
      Log the error details (including stack traces) using a logging framework for better diagnostics.
    3. Return Consistent Error Messages:
      Provide structured JSON error responses that include a message and possibly an error code:
      catch (RestClientException e) {
          logger.error("API request failed for URL {}: {}", url, e.getMessage());
          return "{\"error\": \"Failed to fetch stock price. Please try again later.\"}";
      }
    4. Test Error Scenarios:
      Simulate failures (e.g., by providing an invalid API key) and verify that errors are handled and logged as expected.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions