Class: Audd::ErrorResponse

Inherits:
Model
  • Object
show all
Defined in:
lib/audd/models/error_response.rb

Overview

Envelope returned with status: "error". ResponseParser turns one of these into the matching Audd::ApiError subclass; it is exposed because the exception hands the parsed envelope back on #raw_response.

Instance Attribute Summary

Attributes inherited from Model

#raw

Instance Method Summary collapse

Methods inherited from Model

#==, #[], field, fields, from_json, #hash, #inspect, #to_h

Constructor Details

#initialize(raw) ⇒ ErrorResponse

Returns a new instance of ErrorResponse.



20
21
22
23
# File 'lib/audd/models/error_response.rb', line 20

def initialize(raw)
  super
  @request_params ||= raw["requested_params"]
end

Instance Method Details

#branded_messageObject

Codes 19 and 31337 may carry a "branded" artist/title instead of a real result. It is deliberately not surfaced as a recognition result.



35
36
37
38
39
40
# File 'lib/audd/models/error_response.rb', line 35

def branded_message
  return nil unless result.is_a?(Hash)

  parts = [result["artist"], result["title"]].compact.map(&:to_s).reject(&:empty?)
  parts.empty? ? nil : parts.join("")
end

#error_codeObject



25
26
27
# File 'lib/audd/models/error_response.rb', line 25

def error_code
  dig_error("error_code")
end

#error_messageObject



29
30
31
# File 'lib/audd/models/error_response.rb', line 29

def error_message
  dig_error("error_message")
end