Exception: Speechmatics::Response::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/speechmatics/response/error.rb,
lib/speechmatics/response/error/unknown.rb,
lib/speechmatics/response/error/bad_gateway.rb,
lib/speechmatics/response/error/cannot_align.rb,
lib/speechmatics/response/error/unauthorized.rb,
lib/speechmatics/response/error/invalid_audio.rb,
lib/speechmatics/response/error/job_not_found.rb,
lib/speechmatics/response/error/job_in_progress.rb,
lib/speechmatics/response/error/missing_callback.rb,
lib/speechmatics/response/error/missing_language.rb,
lib/speechmatics/response/error/malformed_request.rb,
lib/speechmatics/response/error/missing_data_file.rb,
lib/speechmatics/response/error/not_alignment_job.rb,
lib/speechmatics/response/error/too_many_requests.rb,
lib/speechmatics/response/error/insufficient_credit.rb,
lib/speechmatics/response/error/service_unavailable.rb,
lib/speechmatics/response/error/internal_server_error.rb,
lib/speechmatics/response/error/product_not_available.rb,
lib/speechmatics/response/error/rejected_on_submission.rb,
lib/speechmatics/response/error/unsupported_output_format.rb

Defined Under Namespace

Classes: BadGateway, CannotAlign, InsufficientCredit, InternalServerError, InvalidAudio, JobInProgress, JobNotFound, MalformedRequest, MissingCallback, MissingDataFile, MissingLanguage, NotAlignmentJob, ProductNotAvailable, RejectedOnSubmission, ServiceUnavailable, TooManyRequests, Unauthorized, Unknown, UnsupportedOutputFormat

Constant Summary collapse

TYPES =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Error

Returns a new instance of Error.



40
41
42
43
# File 'lib/speechmatics/response/error.rb', line 40

def initialize(response)
  @response = response
  super self.class.error_message(response)
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



38
39
40
# File 'lib/speechmatics/response/error.rb', line 38

def response
  @response
end

Class Method Details

.classify(response) ⇒ Object



13
14
15
16
# File 'lib/speechmatics/response/error.rb', line 13

def classify(response)
  klass = TYPES.find { |t| t.matches?(response) } || Unknown
  klass.new(response)
end

.error_message(response) ⇒ Object



31
32
33
34
35
# File 'lib/speechmatics/response/error.rb', line 31

def error_message(response)
  response['error']
rescue
  ''
end

.inherited(subclass) ⇒ Object



9
10
11
# File 'lib/speechmatics/response/error.rb', line 9

def inherited(subclass)
  TYPES << subclass
end

.matches?(response) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
# File 'lib/speechmatics/response/error.rb', line 18

def matches?(response)
  matches_status?(response.raw.status) &&
    matches_message?(error_message(response))
end

.matches_message?(message) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/speechmatics/response/error.rb', line 27

def matches_message?(message)
  self::ERROR_MESSAGE == message
end

.matches_status?(status) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/speechmatics/response/error.rb', line 23

def matches_status?(status)
  self::ERROR_STATUS == status
end