Returns the error array.

@param array $response
@return array the error array with 2 keys: code and message. Should be null if no errors.
329426
protected function fetchResponseError($response)
	{
		if (isset($response['error-code'])) {
			return [
				'code' => $response['error-code'],
				'message' => $response['message'],
			];
		} else if (isset($response['errorCode'])) {
			return [
				'code' => $response['errorCode'],
				'message' => $response['message'],
			];
		}
		return null;
	}
156320
protected function checkResponse(array $response)
    {
        $responseCode = intval(array_get($response, '_curl_info.http_code'));
        $message = array_get($response, 'message');

        if ($responseCode >= 400) {
            $context = ['response_headers' => array_get($response, '_curl_info.response_headers')];
            throw new RestException($responseCode, $message, null, null, $context);
        }
    }
829551
private function parseErrorResponse(ResponseInterface $response): array
    {
        $error = [
            'code' => null,
            'message' => null,
        ];
        // Try to parse Edge error message and error code from the response body.
        $contentTypeHeader = $response->getHeaderLine('Content-Type');
        if ($contentTypeHeader && false !== strpos($contentTypeHeader, 'application/json')) {
            $array = json_decode((string) $response->getBody(), true);
            if (JSON_ERROR_NONE === json_last_error()) {
                if (array_key_exists('fault', $array)) {
                    $error['message'] = $array['fault']['faultstring'] ?? null;
                    $error['code'] = $array['fault']['detail']['errorcode'] ?? null;
                } else {
                    if (array_key_exists('code', $array)) {
                        $error['code'] = $array['code'];
                    }
                    if (array_key_exists('message', $array)) {
                        // It could happen that the returned message by
                        // Apigee Edge is also an array.
                        $error['message'] = is_array($array['message']) ? json_encode($array['message']) : $array['message'];
                    }
                }
            }
        }

        return $error;
    }
157460
public static function decodeHttpResponse($response) {
    $code = $response->getResponseHttpCode();
    $body = $response->getResponseBody();
    $decoded = null;
    
    if ($code != '200' && $code != '201' && $code != '204') {
      $decoded = json_decode($body, true);
      $err = 'Error calling ' . $response->getRequestMethod() . ' ' . $response->getUrl();
      if ($decoded != null && isset($decoded['error']['message'])  && isset($decoded['error']['code'])) {
        // if we're getting a json encoded error definition, use that instead of the raw response
        // body for improved readability
        $err .= ": ({$decoded['error']['code']}) {$decoded['error']['message']}";
      } else {
        $err .= ": ($code) $body";
      }
      throw new Service\Exception($err, $code);
    }
    
    // Only attempt to decode the response, if the response code wasn't (204) 'no content'
    if ($code != '204') {
      $decoded = json_decode($body, true);
      if ($decoded == null) {
        throw new Service\Exception("Invalid json in service response: $body");
      }
    }
    return $decoded;
  }
1020796
private function extractError($response)
    {
        $error = array();
        $response = json_decode($response);
        if (property_exists($response, 'error')) {
            if (is_string($response->error->message)) {
                $message = $response->error->message;
            } elseif (is_object($response->error->message)) {
                $message = $response->error->message->value;
            } else {
                $message = "Unknown error";
            }
            $error['Message'] = $message;
            return $error;
        }
        return null;
    }
483684
private function captchaResponse($response)
    {
        $errors = ['g-recaptcha-response' => ['Oops, something went wrong']];
        foreach ($response->getErrorCodes() as $k => $code) {
            if ($code == 'missing-input-response') {
                $code = 'Please confirm you are not a robot.';
            }
            $errors['g-recaptcha-response'][$k] = $code;
        }

        return new JsonResponse($errors, 422);
    }
272357
public function getResponseArray($response)
    {
        $return = [];

        if (!($response instanceof Response)) {
            $this->errors[] = [
                // this error is coming from us, not the Chargify API response
                'source'    => 'client',
                'attribute' => null,
                'kind'      => 'networking',
                'message'   => 'no response'
            ];

            return $return;
        }

        /**
         * add error for bad status codes
         */
        $code       = $response->getStatusCode();
        $errorCodes = [404, 401, 500];
        if (in_array($code, $errorCodes)) {
            $this->errors[] = [
                // this error is coming from us, not the Chargify API response
                'source'    => 'client',
                'attribute' => null,
                'kind'      => 'status_code',
                'message'   => 'Bad status code: ' . $code
            ];
        }

        $body = $response->getBody();
        $body = trim((string)$body);

        /**
         * Return early if we have an empty body, which we can't turn into an array
         * anyway. This happens in cases where the API returns a 404, and possibly
         * other status codes.
         */
        if (empty($body)) {
            return $return;
        }

        $return = json_decode($body, true);

        // set errors, if any
        if (!empty($return['result']['errors'])) {
            foreach ($return['result']['errors'] as $error) {
                $this->errors[] = $error;
            }
        }

        /**
         * NOTE: There is also, maybe, an errors array nested in $return['meta']['errors']
         *       Why is this API so inconsistent???!!!!!
         */

        return $return;
    }
538683
private function getErrorFromRegData($data)
	{
		$data['username'] = e($data['username']);
		$validator = Validator::make($data, Validators::rulesForRegisterAcc(), Validators::messagesForErrors());
		$userMessages = $validator->messages();

		if ($validator->fails()) {
			$result['errors'] = array(
				'username'        => $userMessages->first('username'),
				'callback'        => $userMessages->first('callback'),
				'email'           => $userMessages->first('email'),
				'password'        => $userMessages->first('password'),
				'confirmPassword' => $userMessages->first('confirmPassword'),
			);

			return $result;
		}

		return null;
	}
727914
private function hasError(array $response): bool
    {
        if (isset($response[self::ERROR])) {
            $this->errorMessage = $response[self::ERROR][self::ERROR_MESSAGE] ?? null;
            $this->errorType = $response[self::ERROR][self::ERROR_TYPE] ?? null;
            $this->errorCode = $response[self::ERROR][self::ERROR_CODE] ?? null;
            $this->errorSubcode = $response[self::ERROR][self::ERROR_SUBCODE] ?? null;
            $this->errorFbtraceId = $response[self::ERROR][self::ERROR_FBTRACE_ID] ?? null;

            return true;
        }

        return false;
    }
116187
private function resolveResponseArray(array $response)
    {
        if ($count = count($response)) {
            if ($count === 1) {
                $response = $response[0];
            }
        }
        $this->firing[] = $response;

        return $response;
    }
558467
public static function getErrorDetails(ResponseInterface $response)
    {
        $responseInfoProperties = [
            // Platform.sh API errors.
            'message',
            'detail',
            // RESTful module errors.
            'title',
            'type',
            // OAuth2 errors.
            'error',
            'error_description',
        ];

        $details = '';

        $response->getBody()->seek(0);
        $contents = $response->getBody()->getContents();

        try {
            $json = \GuzzleHttp\json_decode($contents, true);
            foreach ($responseInfoProperties as $property) {
                if (!empty($json[$property])) {
                    $value = $json[$property];
                    $details .= " [$property] " . (is_scalar($value) ? $value : json_encode($value));
                }
            }
        } catch (\InvalidArgumentException $parseException) {
            // Occasionally the response body may not be JSON.
            if ($contents) {
                $details .= " [extra] Non-JSON response body";
                $details .= " [body] " . $contents;
            }
            else {
                $details .= " [extra] Empty response body";
            }
        }

        return $details;
    }
274832
public function get_errors($key = null, string $format = ':message'): array
    {
        if (null === $key) {
            return \array_map(
                function ($vals) {
                    return \array_values($vals);
                },
                $this->validation->errors()->toArray()
            );
        }

        return $this->validation->errors()->get($key, $format);
    }
514176
protected function unserializeResponse($response = null){
        switch($this->getEndpoint()){
            case "json":
                return json_decode($response,true);
                break;
            case "xml":
                return (array) json_decode(json_encode(simplexml_load_string($response, null, LIBXML_NOCDATA)),true);
                break;
            default:
                throw new \ErrorException('Invalid response type');
                break;
        }
    }
258604
private function decode(array $response)
    {
        $decodedBody = json_decode($response['body'], true);

        if (null === $decodedBody) {
            return new WP_Error('decode-error', 'Unable to decode response body', $response);
        }

        if (true !== $decodedBody['success']) {
            return $this->wpErrorFor($decodedBody['errors'], $response);
        }

        return $response;
    }
860902
protected function getErrorMessage(Response $response)
    {
        if ($response->hasBody()) {
            if (is_array($response->body)) {
                return isset($response->body['error']['message']) ? $response->body['error']['message'] : $response->raw_body;
            } else {
                return isset($response->body->error->message) ? $response->body->error->message : $response->raw_body;
            }
        } else {
            return $response->raw_body;
        }
    }
177417
protected function validateResponse($response)
    {
        if (isset($response->code) && isset($response->message)) {
            if ($response->code == $this->validResponseCode &&
                $response->message == $this->validResponseMessage
            ) {
                // serial keys are valid
                $valid = true;
            } else {
                // serial keys are not valid
                $this->setErrorMessage(\OxidEsales\Eshop\Core\Registry::getLang()->translateString('OLC_ERROR_SERIAL_NOT_VALID'));
                $valid = false;
            }
        } else {
            // validation result is unknown
            throw new \OxidEsales\Eshop\Core\Exception\StandardException('OLC_ERROR_RESPONSE_NOT_VALID');
        }

        return $valid;
    }
1065864
private static function handleErrors($response)
    {
        switch ($response->getStatusCode()) {
            case 200:
                return json_decode($response->getBody());
                break;
            case 401:
                throw new UnauthorizedException('Unauthorized (Invalid API key or insufficient permissions)');
                break;
            case 404:
                throw new NotFoundException('Object not found within your account scope');
                break;
            case 406:
                throw new InvalidFormatException('Requested format is not supported - request JSON or XML only');
                break;
            case 422:
                throw new ValidationException('Validation error(s) for create or update method');
                break;
            case 500:
                throw new ServerException('Something went wrong on Challonge\'s end');
                break;
            default:
                $decodedResponse = json_decode($response->getBody());
                throw new UnexpectedErrorException($decodedResponse);
                break;
        }
    }