private function handleError($e)
	{
		// if there's no response attached to the exception,
		// we will assume that the request was never sent and
		// thus will throw a network error
		if( ! $e->hasResponse())
		{
			throw new Errors\NetworkError;
		}

		// if there's a response attached to the exception,
		// we will figure out which error to throw based on
		// the HTTP status code of response
		$response = $e->getResponse();
		$body = $response->json();
		switch($response->getStatusCode())
		{
			case 400:
				throw new Errors\InvalidRequestError($body['error']['message'], $body['error']['code'], $body['error']['type']);
				break;

			case 401:
				throw new Errors\AuthenticationError($body['error']['message'], $body['error']['code'], $body['error']['type']);
				break;
				
			case 403:
				throw new Errors\ForbiddenError($body['error']['message'], $body['error']['code'], $body['error']['type']);
				break;

			case 404:
				throw new Errors\NotFoundError($body['error']['message'], $body['error']['code'], $body['error']['type']);
				break;

			case 500:
				throw new Errors\ServiceError($body['error']['message'], $body['error']['code'], $body['error']['type']);
				break;

			// for backwards compatibility, we will handle other
			// HTTP status codes too (to keep the SDK working,
			// even when we send more variants of HTTP status codes
			// through API)
			default:
				return $this->handleUnknownError($e);
		}
	}
private function handleError($e)
	{
		// if there's no response attached to the exception,
		// we will assume that the request was never sent and
		// thus will throw a network error
		if( ! $e->hasResponse())
		{
			throw new Errors\NetworkError;
		}

		// if there's a response attached to the exception,
		// we will figure out which error to throw based on
		// the HTTP status code of response
		$response = $e->getResponse();
		$body = $response->json();
		switch($response->getStatusCode())
		{
			case 400:
				throw new Errors\InvalidRequestError($body['error']['message'], $body['error']['code'], $body['error']['type']);
				break;

			case 401:
				throw new Errors\AuthenticationError($body['error']['message'], $body['error']['code'], $body['error']['type']);
				break;
				
			case 403:
				throw new Errors\ForbiddenError($body['error']['message'], $body['error']['code'], $body['error']['type']);
				break;

			case 404:
				throw new Errors\NotFoundError($body['error']['message'], $body['error']['code'], $body['error']['type']);
				break;

			case 500:
				throw new Errors\ServiceError($body['error']['message'], $body['error']['code'], $body['error']['type']);
				break;

			// for backwards compatibility, we will handle other
			// HTTP status codes too (to keep the SDK working,
			// even when we send more variants of HTTP status codes
			// through API)
			default:
				return $this->handleUnknownError($e);
		}
	}
private function handleError ( $ e ) { // if there's no response attached to the exception, // we will assume that the request was never sent and // thus will throw a network error if ( ! $ e -> hasResponse ( ) ) { throw new Errors \ NetworkError ; } // if there's a response attached to the exception, // we will figure out which error to throw based on // the HTTP status code of response $ response = $ e -> getResponse ( ) ; $ body = $ response -> json ( ) ; switch ( $ response -> getStatusCode ( ) ) { case 400 : throw new Errors \ InvalidRequestError ( $ body [ 'error' ] [ 'message' ] , $ body [ 'error' ] [ 'code' ] , $ body [ 'error' ] [ 'type' ] ) ; break ; case 401 : throw new Errors \ AuthenticationError ( $ body [ 'error' ] [ 'message' ] , $ body [ 'error' ] [ 'code' ] , $ body [ 'error' ] [ 'type' ] ) ; break ; case 403 : throw new Errors \ ForbiddenError ( $ body [ 'error' ] [ 'message' ] , $ body [ 'error' ] [ 'code' ] , $ body [ 'error' ] [ 'type' ] ) ; break ; case 404 : throw new Errors \ NotFoundError ( $ body [ 'error' ] [ 'message' ] , $ body [ 'error' ] [ 'code' ] , $ body [ 'error' ] [ 'type' ] ) ; break ; case 500 : throw new Errors \ ServiceError ( $ body [ 'error' ] [ 'message' ] , $ body [ 'error' ] [ 'code' ] , $ body [ 'error' ] [ 'type' ] ) ; break ; // for backwards compatibility, we will handle other // HTTP status codes too (to keep the SDK working, // even when we send more variants of HTTP status codes // through API) default : return $ this -> handleUnknownError ( $ e ) ; } }
Handles the error by throwing proper exception

@param  GuzzleHttp\Exception\RequestException $e
@return null
@throws Horntell\Errors\NetworkError If original exception has no response attached to it
@throws Horntell\Errors\InvalidRequestException If HTTP Status Code is 400
@throws Horntell\Errors\AuthenticationException If HTTP Status Code is 401
@throws Horntell\Errors\ForbiddenException If HTTP Status Code is 403
@throws Horntell\Errors\NotFoundException If HTTP Status Code is 404
@throws Horntell\Errors\ServiceException If HTTP Status Code is 500
Handles the error by throwing proper exception