Class: ParseError

Inherits:
Object
  • Object
show all
Defined in:
lib/parse_resource/parse_error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, msg = "") ⇒ ParseError

Returns a new instance of ParseError.

Parameters:

  • an (String)

    error code, e.g. “400”

  • an (Object)

    optional error mesg/object.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/parse_resource/parse_error.rb', line 10

def initialize(code, msg="")
  @msg = msg
  @code = code
  case code.to_s
  when "111"
    @error = "Invalid type."
  when "135"
    @error = "Unknown device type."
  when "202"
    @error = "Username already taken."
  when "400"
    @error = "Bad Request: The request cannot be fulfilled due to bad syntax."
  when "401"
    @error = "Unauthorized: Check your App ID & Master Key."
  when "403"
    @error = "Forbidden: You do not have permission to access or modify this."
  when "408"
    @error = "Request Timeout: The request was not completed within the time the server was prepared to wait."
  when "415"
    @error = "Unsupported Media Type"
  when "500"
    @error = "Internal Server Error"
  when "502"
    @error = "Bad Gateway"
  when "503"
    @error = "Service Unavailable"
  when "508"
    @error = "Loop Detected"
  else
    @error = "Unknown Error"
    raise "Parse error #{code}: #{@error} #{@msg}"
  end
end

Instance Attribute Details

#codeObject

ParseError actually represents both HTTP & parse.com error codes. If the HTTP response is 400, one can inspect the first element of the error converted to_array for the HTTP error code and the 2nd element for the parse error response.



6
7
8
# File 'lib/parse_resource/parse_error.rb', line 6

def code
  @code
end

#errorObject

ParseError actually represents both HTTP & parse.com error codes. If the HTTP response is 400, one can inspect the first element of the error converted to_array for the HTTP error code and the 2nd element for the parse error response.



6
7
8
# File 'lib/parse_resource/parse_error.rb', line 6

def error
  @error
end

#msgObject

ParseError actually represents both HTTP & parse.com error codes. If the HTTP response is 400, one can inspect the first element of the error converted to_array for the HTTP error code and the 2nd element for the parse error response.



6
7
8
# File 'lib/parse_resource/parse_error.rb', line 6

def msg
  @msg
end

Instance Method Details

#to_arrayObject



44
45
46
# File 'lib/parse_resource/parse_error.rb', line 44

def to_array
  [ @code, @msg ]
end