{"record":{"id":"3e62403bda771796","repo":"arsduo/koala","slug":"servererror-new-response-status-response-body","errorCode":null,"errorMessage":"ServerError.new(response.status, response.body)","messagePattern":"ServerError\\.new\\(response\\.status, response\\.body\\)","errorType":"exception","errorClass":"Koala::Facebook::ServerError","httpStatus":500,"severity":"error","filePath":"lib/koala/oauth.rb","lineNumber":311,"sourceCode":"            else\n              raise\n            end\n          end\n\n          components.merge(token_info) if token_info\n        else\n          Koala::Utils.logger.warn(\"Signed cookie didn't contain Facebook OAuth code! Components: #{components}\")\n          nil\n        end\n      end\n\n      def fetch_token_string(args, post = false, endpoint = \"access_token\", options = {})\n        response = Koala.make_request(\"/oauth/#{endpoint}\", {\n          :client_id => @app_id,\n          :client_secret => @app_secret\n        }.merge!(args), post ? \"post\" : \"get\", {:use_ssl => true}.merge!(options))\n\n        raise ServerError.new(response.status, response.body) if response.status >= 500\n        raise OAuthTokenRequestError.new(response.status, response.body) if response.status >= 400\n\n        response.body\n      end\n\n      # base 64\n      # directly from https://github.com/facebook/crypto-request-examples/raw/master/sample.rb\n      def base64_url_decode(str)\n        str += '=' * (4 - str.length.modulo(4))\n        Base64.decode64(str.tr('-_', '+/'))\n      end\n\n      def server_url(type)\n        url = \"https://#{Koala.config.send(type)}\"\n        if version = Koala.config.api_version\n          \"#{url}/#{version}\"\n        else\n          url","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/arsduo/koala/blob/47d052063ef8b5644fb59e279da0b52687999f55/lib/koala/oauth.rb#L293-L329","documentation":"fetch_token_string is the shared worker behind every server-side token call (get_access_token_info, get_app_access_token_info, exchange_access_token_info, generate_client_code). It hits /oauth/<endpoint> over SSL and raises Koala::Facebook::ServerError (an APIError carrying http_status and response_body) whenever Facebook responds with status 500 or above. A 5xx here means the failure sits on the Facebook side or in front of it (outage, rate-limit infrastructure, deprecated API version), not in your OAuth parameters.","triggerScenarios":"Any token endpoint call returning 5xx: get_access_token(code) or exchange_access_token(token) during a Facebook platform incident; Koala.config.api_version pinned to a Graph version Facebook has removed so /oauth/access_token starts failing; an upstream proxy returning 502 or 504 for graph.facebook.com.","commonSituations":"Graph API outages (check the Facebook developer status page); deprecation deadlines passing with an old Koala or an old api_version; corporate egress proxies; retry storms amplifying an incident.","solutions":["Check Facebook platform status before debugging code; 5xx from /oauth endpoints usually tracks a known incident.","Retry with capped exponential backoff and jitter; these responses are transient by nature.","Verify Koala.config.api_version points to a live Graph API version and upgrade the Koala gem if needed.","Log e.http_status and e.response_body to confirm which endpoint and status are failing."],"exampleFix":"// before\ntoken = @oauth.exchange_access_token(old_token)\n\n// after\nattempts = 0\nbegin\n  attempts += 1\n  token = @oauth.exchange_access_token(old_token)\nrescue Koala::Facebook::ServerError => e\n  raise if attempts >= 3\n  sleep(2 ** attempts + rand(2))\n  retry\nend","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"begin\n  @oauth.exchange_access_token(token)\nrescue Koala::Facebook::ServerError => e\n  # 5xx: transient; this endpoint is idempotent so retry with backoff\n  retry_with_backoff(max_attempts: 3) { @oauth.exchange_access_token(token) }\nend","preventionTips":["Wrap token calls in bounded retry-with-backoff for 5xx only, and cap total attempts","Do not blind-retry code redemption more than once; a 5xx can mask a success and OAuth codes are single-use","Watch Facebook platform status and Graph version deprecation notices; bump api_version before cutoffs"],"tags":["oauth","http-5xx","transient","retry","koala","facebook"],"backgroundTag":"server-error-5xx","analyzedSha":"47d052063ef8b5644fb59e279da0b52687999f55","analyzedAt":"2026-08-23T10:19:03.891Z","schemaVersion":2},"datasetVersion":"2026-08-23T13:39:53.451Z"}