Class: Facebook::Middleware::ExceptionRaiser
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Facebook::Middleware::ExceptionRaiser
- Defined in:
- lib/facebook-client/middleware/exception_raiser.rb
Overview
Raise beautiful exceptions
Instance Method Summary collapse
Instance Method Details
#call(env) ⇒ 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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/facebook-client/middleware/exception_raiser.rb', line 19 def call(env) begin @app.call(env) rescue Faraday::Error::ClientError => e # Error codes are based upon: # http://fbdevwiki.com/wiki/Error_codes#Error_Code_Table fb_error_code = e.response[:body].try(:[], 'error').try(:[], 'code') # Translate our error code into an exception exception = case fb_error_code ## (0-99) General Errors when 2 Facebook::ServiceError when 3 Facebook::UnknownMethodError when 4, 18, 9, 17 Facebook::RequestLimitError when 10 Facebook::ApplicationPermissionError when 11 Facebook::MethodDeprecatedError when 0..99 Facebook::GeneralError ## (100-199) Parameter Errors when 101 Facebook::InvalidAPIKeyError when 102 Facebook::InvalidSessionKeyError when 190 Facebook::InvalidAccessTokenError when 100..199 Facebook::ParameterError ## (200-299) User Permission Errors when 200 Facebook::PermissionError when 212 Facebook::OfflineAccessPermissionError when 200..299 Facebook::UserPermissionError ## (300-399) Data Editing Errors when 300..399 Facebook::DataEditingError ## (400-449) Authentication Errors when 400..449 Facebook::AuthenticationError ## (450-455) Session Errors when 450..455 Facebook::SessionError ## (500-599) Application Messaging Errors when 500..599 Facebook::ApplicationMessagingError ## (600-699) FQL Errors when 600..699 Facebook::FQLError ## (700-749) Ref Errors when 700..749 Facebook::RefError ## (750-799) Application Integration Errors when 750..799 Facebook::ApplicationIntegrationError ## (900-949) Application Information Errors when 900..949 Facebook::ApplicationInformationError ## (950-999) Batch API Errors when 950..999 Facebook::BatchAPIError else Facebook::GenericException end raise exception, e.response rescue Saddle::TimeoutError => e raise Facebook::TimeoutError, e.response end end |