@@ -3,9 +3,70 @@ class Client
33 module Core
44 API_VERSION = "1"
55
6+ attr_reader :error_table
7+
68 def get ( path , options = auth_query )
7- self . class . get ( path , options )
9+ response = self . class . get ( path , options )
10+ case response . code
11+ when 200
12+ response
13+ # when 401
14+ # raise Buff::UnauthorizeRequest
15+ else
16+ handle_response_code ( response )
17+ end
18+ end
19+
20+ def handle_response_code ( response )
21+ error = Hashie ::Mash . new ( response . body )
22+ if ERROR_TABLE [ error . code ]
23+ error_explanation = "Buffer API Error Code: #{ error . code } \n "
24+ error_explanation += "Description: #{ error . error } "
25+ else
26+ error_explanation = "Buffer API Unknown Error in Response"
27+ end
28+
29+ raise Buff ::APIError , error_explanation
830 end
31+
32+ def self . error_table
33+ @error_table ||= ERROR_TABLE
34+ end
35+
36+ ERROR_TABLE = {
37+ "403" => "Permission denied." ,
38+ "404" => "Endpoint not found." ,
39+ "405" => "Method not allowed." ,
40+ "1000" => "An unknown error occurred." ,
41+ "1001" => "Access token required." ,
42+ "1002" => "Not within application scope." ,
43+ "1003" => "Parameter not recognized." ,
44+ "1004" => "Required parameter missing." ,
45+ "1005" => "Unsupported response format." ,
46+ "1006" => "Parameter value not within bounds." ,
47+ "1010" => "Profile could not be found." ,
48+ "1011" => "No authorization to access profile." ,
49+ "1012" => "Profile did not save successfully." ,
50+ "1013" => "Profile schedule limit reached." ,
51+ "1014" => "Profile limit for user has been reached." ,
52+ "1015" => "Profile could not be destroyed." ,
53+ "1020" => "Update could not be found." ,
54+ "1021" => "No authorization to access update." ,
55+ "1022" => "Update did not save successfully." ,
56+ "1023" => "Update limit for profile has been reached." ,
57+ "1024" => "Update limit for team profile has been reached." ,
58+ "1025" => "Update was recently posted, can't post duplicate content." ,
59+ "1026" => "Update must be in error status to requeue." ,
60+ "1028" => "Update soft limit for profile reached." ,
61+ "1029" => "Event type not supported." ,
62+ "1030" => "Media filetype not supported." ,
63+ "1031" => "Media filesize out of acceptable range." ,
64+ "1032" => "Unable to post image to LinkedIn group(s)." ,
65+ "1042" => "User did not save successfully." ,
66+ "1050" => "Client could not be found." ,
67+ "1051" => "No authorization to access client."
68+ }
69+
970 end
1071 end
1172end
0 commit comments