Error handling for Razorpay API.
This module provides structured error handling for Razorpay API responses. It converts Razorpay error codes into specific error types and provides detailed error information.
Error Structure
Razorpay errors include:
code: Error code (e.g., "BAD_REQUEST_ERROR")description: Human-readable error descriptionfield: Field that caused the error (if applicable)step: Step in which error occurredreason: Reason for the errormetadata: Additional error metadatahttp_status_code: HTTP status codehttp_body: Raw HTTP response body
Examples
case RazorpayEx.Payment.fetch("invalid_id") do
{:ok, payment} ->
# Handle success
{:error, %RazorpayEx.Error{code: "BAD_REQUEST_ERROR"} = error} ->
IO.puts("Bad request: #{error.description}")
{:error, error} ->
IO.puts("Unknown error: #{inspect(error)}")
end
Summary
Functions
Creates an error from a Razorpay error response.
Returns a string representation of the error.
Creates a new error.
Types
Functions
Creates an error from a Razorpay error response.
Parameters
error_map: Error map from Razorpay APIstatus_code: HTTP status code
Examples
error = Razorpay.Error.from_map(%{
"code" => "BAD_REQUEST_ERROR",
"description" => "Invalid payment id"
}, 400)
Returns a string representation of the error.
Creates a new error.
Parameters
type: Error type atom or stringdescription: Error descriptionstatus_code: HTTP status code (default: 0)
Examples
error = RazorpayEx.Error.new(:network_error, "Connection failed")
error = RazorpayEx.Error.new("BAD_REQUEST", "Invalid input", 400)