class GreatSchools::Error

GreatSchools Error

Encompass any errors sent back by the GreatSchools API.

GreatSchools sends back XML to all API requests. The error response looks like:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<error>
  <errorCode>3</errorCode>
  <faultString>Invalid API key.</faultString>
  <date>2013/11/22</date>
  <call>/reviews/city/CA/Foster-City</call>
</error>

Examples

The most common error is trying to request data that your API key does not have access to.

GreatSchools::API.key = 'INVALID_KEY'
GreatSchools::Review.for_city('CA', 'Foster City')
# => #<GreatSchools::Error error_code: "3", fault_string: "Invalid API key.", call: "/reviews/city/CA/Foster-City", date: "2013/11/22">

Attributes

call[R]
date[R]
error_code[R]

Public Class Methods

new(response) click to toggle source

Creates a new GreatSchools::Error from a parsed HTTParty response. The faultString is used as the error message.

Attributes

  • response - a parsed response object from HTTParty

– TODO: add error handling - ensure we have a Hash, use fetch with defaults ++

Calls superclass method
# File lib/great_schools/error.rb, line 39
def initialize(response)
  super(response['error']['faultString'])

  @call = response['error']['call']
  @date = response['error']['date']
  @error_code = response['error']['errorCode']
end