Sha256: 3e06fec387567414c8e9b58b3afdc7adb61abb4044fe0a4cd06e5e622c2bb7ae
Contents?: true
Size: 1.46 KB
Versions: 2
Compression:
Stored size: 1.46 KB
Contents
module ReadabilityParser class Error < StandardError class ClientError < Error def initialize(error=nil) parsed_error = parse_error(error) http_error = error.response[:status].to_i if ERROR_MAP.has_key?(http_error) raise ERROR_MAP[http_error].new(parsed_error[:messages]) else super end end def parse_error(error) JSON.parse(error.response[:body], :symbolize_names => true) end end # ClientError class ConfigurationError < ReadabilityParser::Error; end # Raised when ReadabilityParser returns a 400 HTTP status code class BadRequest < ReadabilityParser::Error; end # Raised when ReadabilityParser returns a 401 HTTP status code class UnauthorizedRequest < ReadabilityParser::Error; end # Raised when ReadabilityParser returns a 403 HTTP status code class Forbidden < ReadabilityParser::Error; end # Raised when ReadabilityParser returns a 404 HTTP status code class NotFound < ReadabilityParser::Error; end # Raised when ReadabilityParser returns a 500 HTTP status code class InternalServerError < ReadabilityParser::Error; end ERROR_MAP = { 400 => ReadabilityParser::Error::BadRequest, 401 => ReadabilityParser::Error::UnauthorizedRequest, 403 => ReadabilityParser::Error::Forbidden, 404 => ReadabilityParser::Error::NotFound, 500 => ReadabilityParser::Error::InternalServerError } end # Error end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
readability_parser-0.0.2 | lib/readability_parser/error.rb |
readability_parser-0.0.1 | lib/readability_parser/error.rb |