@@ -167,26 +167,33 @@ def self.handle_json_error(rbody, e)
167167 end
168168 end
169169
170+ # Handle errors returned by the ChargeBee API.
171+ #
172+ # @param rcode [Integer] HTTP status code.
173+ # @param rbody [String] HTTP response body.
174+ #
175+ # @return [ChargeBee::Error] Appropriate ChargeBee error object.
170176 def self . handle_for_error ( rcode , rbody )
171177 return Error . new ( "No response returned by ChargeBee API. HTTP status code: #{ rcode } " ) if rcode == 204
178+ return ForbiddenError . new ( "Access forbidden. You do not have permission to access this resource." ) if rcode == 403
172179 begin
173180 error_obj = JSON . parse ( rbody )
174181 error_obj = Util . symbolize_keys ( error_obj )
175182 rescue Exception => e
176- raise Error . new ( "Error response not in JSON format. The http status code is #{ rcode } \n #{ rbody . inspect } " , e )
183+ return Error . new ( "Error response not in JSON format. The http status code is #{ rcode } \n #{ rbody . inspect } " , e )
177184 end
178- type = error_obj [ :type ]
179- case type
185+
186+ case error_obj [ : type]
180187 when "payment"
181- raise PaymentError . new ( rcode , error_obj )
188+ PaymentError . new ( rcode , error_obj )
182189 when "operation_failed"
183- raise OperationFailedError . new ( rcode , error_obj )
190+ OperationFailedError . new ( rcode , error_obj )
184191 when "invalid_request"
185- raise InvalidRequestError . new ( rcode , error_obj )
192+ InvalidRequestError . new ( rcode , error_obj )
186193 when "ubb_batch_ingestion_invalid_request"
187- raise UbbBatchIngestionInvalidRequestError . new ( rcode , error_obj )
194+ UbbBatchIngestionInvalidRequestError . new ( rcode , error_obj )
188195 else
189- raise APIError . new ( rcode , error_obj )
196+ APIError . new ( rcode , error_obj )
190197 end
191198 end
192199
0 commit comments