mrsool / zatca

An unofficial Ruby library for generating ZATCA e-invoices, QR Codes, and submitting e-invoices to ZATCA's servers.
MIT License
36 stars 12 forks source link

Fix Parsing of HTTPX::ErrorResponse and Add Hooks for Advanced Logging #25

Closed obahareth closed 6 months ago

obahareth commented 6 months ago

There are usecases when users of the SDK need to perform custom logic before the request is sent or response is parsed, so they can add context to exception monitoring platforms.

This change also adds the following two hooks:

These hooks can be used like so:

client = ZATCA::Client.new(username: "user", password: "pass", verbose: true)

client.before_submitting_request = proc do |method, url, body, headers|
  # method is a symbol
  # url is a string
  # body and headers are hashes
end

client.before_parsing_response = proc do |response|
  # Response is an instance of HTTPX::Response or HTTPX::ErrorResponse
end