Exception: Clarifai::Rails::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/clarifai/rails/error.rb

Defined Under Namespace

Classes: AllError, ClientError, PartialError, ServerError, TokenAppInvalid

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, text) ⇒ Error

Returns a new instance of Error.



6
7
8
9
# File 'lib/clarifai/rails/error.rb', line 6

def initialize(code, text)
  @error_code = code
  @error_text = text
end

Class Method Details

.detector(status_code) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/clarifai/rails/error.rb', line 19

def self.detector(status_code)
  error = case status_code
          when "PARTIAL_ERROR"
            PartialError.new(200, "Some images in request have failed. Please review the error messages per image.")
          when "ALL_ERROR"
            AllError.new(400, "Bad request.")
          when "CLIENT_ERROR"
            error_code = 400
            error_text = "Data loading failed, see results for details."
          when "SERVER_ERROR"
            error_code = 500
            error_text = "Data failed to process, see results for details."
          when "TOKEN_APP_INVALID"
            error_code = 401
            error_text = "Application for this token is not valid. Please ensure that you are using ID and SECRET from same application."
          when "TOKEN_EXPIRED"
            error_code = 401
            error_text = "Token has expired, you must generate a new access token."
          when "TOKEN_INVALID"
            error_code = 401
            error_text = "Token is not valid. Please use valid tokens for a application in your account."
          when "TOKEN_NONE"
            error_code = 401
            error_text = "Authentication credentials were not provided in request."
          when "TOKEN_NO_SCOPE"
            error_code = 401
            error_text = "Token does not have the required scope to access resources."
          end

  return error if error.present?
end

Instance Method Details

#codeObject



11
12
13
# File 'lib/clarifai/rails/error.rb', line 11

def code
  @error_code
end

#messageObject



15
16
17
# File 'lib/clarifai/rails/error.rb', line 15

def message
  @error_text
end