Exception: WebApiError

Inherits:
SteamCondenserError show all
Defined in:
lib/errors/web_api_error.rb

Overview

This error is raised when a Steam Web API request or a related action fails. This can have various reasons like an invalid Web API key or a broken request.

See Also:

Author:

  • Sebastian Staudt

Instance Attribute Summary

Attributes inherited from SteamCondenserError

#cause

Instance Method Summary collapse

Constructor Details

#initialize(cause, status_code = nil, status_message = '') ⇒ WebApiError

Creates a new ‘WebApiError` with an error message according to the given `cause`. If this cause is `:status_bad` (which will origin from the Web API itself) or `:http_error` the details about this failed request will be taken from `status_code` and `status_message`.

Parameters:

  • cause (:http_error, :invalid_key, :status_bad, :unauthorized)

    A symbolic name for the problem which caused this error:

    • ‘:http_error`: An error during the HTTP request itself will result

      in an error with this reason.
      
    • ‘:invalid_key`: This occurs when trying to set a Web API key that

      isn't valid, i.e. a 128 bit integer in a hexadecimal string.
      
    • ‘:status_bad`: This is caused by a successful request that fails for some Web API internal reason (e.g. an invalid argument). Details about this failed request will be taken from `status_code` and `status_message`.

    • ‘:unauthorized`: This happens when a Steam Web API request is rejected as unauthorized. This most likely means that you did not specify a valid Web API key using WebApi.api_key=. A Web API key can be obtained from steamcommunity.com/dev/apikey.

    Other undefined reasons will cause a generic error message.

  • status_code (Fixnum) (defaults to: nil)

    The HTTP status code returned by the Web API

  • status_message (String) (defaults to: '')

    The status message returned in the response



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/errors/web_api_error.rb', line 40

def initialize(cause, status_code = nil, status_message = '')
  case cause
    when :http_error then
      message = "The Web API request has failed due to an HTTP error: #{status_message} (status code: #{status_code})."
    when :invalid_key then
      message = 'This is not a valid Steam Web API key.'
    when :status_bad then
      message = "The Web API request failed with the following error: #{status_message} (status code: #{status_code})."
    when :unauthorized then
      message = 'Your Web API request has been rejected. You most likely did not specify a valid Web API key.'
    else
      message = 'An unexpected error occured while executing a Web API request.'
  end

  super message
end