@@ -43,6 +43,9 @@ class APIError < OpenAI::Errors::Error
4343 # @return [Integer, nil]
4444 attr_accessor :status
4545
46+ # @return [Hash{String=>String}, nil]
47+ attr_accessor :headers
48+
4649 # @return [Object, nil]
4750 attr_accessor :body
4851
@@ -59,13 +62,15 @@ class APIError < OpenAI::Errors::Error
5962 #
6063 # @param url [URI::Generic]
6164 # @param status [Integer, nil]
65+ # @param headers [Hash{String=>String}, nil]
6266 # @param body [Object, nil]
6367 # @param request [nil]
6468 # @param response [nil]
6569 # @param message [String, nil]
66- def initialize ( url :, status : nil , body : nil , request : nil , response : nil , message : nil )
70+ def initialize ( url :, status : nil , headers : nil , body : nil , request : nil , response : nil , message : nil )
6771 @url = url
6872 @status = status
73+ @headers = headers
6974 @body = body
7075 @request = request
7176 @response = response
@@ -98,13 +103,15 @@ class APIConnectionError < OpenAI::Errors::APIError
98103 #
99104 # @param url [URI::Generic]
100105 # @param status [nil]
106+ # @param headers [Hash{String=>String}, nil]
101107 # @param body [nil]
102108 # @param request [nil]
103109 # @param response [nil]
104110 # @param message [String, nil]
105111 def initialize (
106112 url :,
107113 status : nil ,
114+ headers : nil ,
108115 body : nil ,
109116 request : nil ,
110117 response : nil ,
@@ -119,13 +126,15 @@ class APITimeoutError < OpenAI::Errors::APIConnectionError
119126 #
120127 # @param url [URI::Generic]
121128 # @param status [nil]
129+ # @param headers [Hash{String=>String}, nil]
122130 # @param body [nil]
123131 # @param request [nil]
124132 # @param response [nil]
125133 # @param message [String, nil]
126134 def initialize (
127135 url :,
128136 status : nil ,
137+ headers : nil ,
129138 body : nil ,
130139 request : nil ,
131140 response : nil ,
@@ -140,21 +149,24 @@ class APIStatusError < OpenAI::Errors::APIError
140149 #
141150 # @param url [URI::Generic]
142151 # @param status [Integer]
152+ # @param headers [Hash{String=>String}, nil]
143153 # @param body [Object, nil]
144154 # @param request [nil]
145155 # @param response [nil]
146156 # @param message [String, nil]
147157 #
148158 # @return [self]
149- def self . for ( url :, status :, body :, request :, response :, message : nil )
150- kwargs = {
151- url : url ,
152- status : status ,
153- body : body ,
154- request : request ,
155- response : response ,
156- message : message
157- }
159+ def self . for ( url :, status :, headers :, body :, request :, response :, message : nil )
160+ kwargs =
161+ {
162+ url : url ,
163+ status : status ,
164+ headers : headers ,
165+ body : body ,
166+ request : request ,
167+ response : response ,
168+ message : message
169+ }
158170
159171 case status
160172 in 400
@@ -198,18 +210,20 @@ def self.for(url:, status:, body:, request:, response:, message: nil)
198210 #
199211 # @param url [URI::Generic]
200212 # @param status [Integer]
213+ # @param headers [Hash{String=>String}, nil]
201214 # @param body [Object, nil]
202215 # @param request [nil]
203216 # @param response [nil]
204217 # @param message [String, nil]
205- def initialize ( url :, status :, body :, request :, response :, message : nil )
218+ def initialize ( url :, status :, headers : , body :, request :, response :, message : nil )
206219 message ||= OpenAI ::Internal ::Util . dig ( body , :message ) { { url : url . to_s , status : status , body : body } }
207220 @code = OpenAI ::Internal ::Type ::Converter . coerce ( String , OpenAI ::Internal ::Util . dig ( body , :code ) )
208221 @param = OpenAI ::Internal ::Type ::Converter . coerce ( String , OpenAI ::Internal ::Util . dig ( body , :param ) )
209222 @type = OpenAI ::Internal ::Type ::Converter . coerce ( String , OpenAI ::Internal ::Util . dig ( body , :type ) )
210223 super (
211224 url : url ,
212225 status : status ,
226+ headers : headers ,
213227 body : body ,
214228 request : request ,
215229 response : response ,
0 commit comments