-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from qixotic/error
Make ParseError a little more useful & fix to_array
- Loading branch information
Showing
4 changed files
with
31 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,42 @@ | ||
class ParseError | ||
# 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. | ||
|
||
# @param [String] an error code, e.g. "400" | ||
# @param [Object] an optional error mesg/object. | ||
def initialize(code, msg="") | ||
@msg = msg | ||
@code = code | ||
case code | ||
when "400" | ||
@error = "Bad Request: The request cannot be fulfilled due to bad syntax." | ||
if msg.empty? | ||
@msg = "Bad Request: The request cannot be fulfilled due to bad syntax." | ||
end | ||
# otherwise we should have supplied the Parse msg JSON response. | ||
when "401" | ||
@error = "Unauthorized: Check your App ID & Master Key." | ||
@msg = "Unauthorized: Check your App ID & Master Key." | ||
when "403" | ||
@error = "Forbidden: You do not have permission to access or modify this." | ||
@msg = "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" | ||
@msg = "Unsupported Media Type" | ||
when "500" | ||
@error = "Internal Server Error" | ||
@msg = "Internal Server Error" | ||
when "502" | ||
@error = "Bad Gateway" | ||
@msg = "Bad Gateway" | ||
when "503" | ||
@error = "Service Unavailable" | ||
@msg = "Service Unavailable" | ||
when "508" | ||
@error = "Loop Detected" | ||
@msg = "Loop Detected" | ||
else | ||
@error = "Unknown Error" | ||
raise "Parse error #{code}: #{@error}" | ||
@msg = "Unknown Error" | ||
raise "Parse msg #{code}: #{@error}" | ||
end | ||
end | ||
|
||
def to_array | ||
@error[1] = @error[1] + " " + @msg | ||
@error | ||
return [@code, @msg] | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters