/** * Send request to Moneybird * * @access protected * @return string * @param string $url * @param string $method (GET|POST|PUT|DELETE) * @param string $data */ protected function request($url, $method, $data = null) { $this->testLogin(); try { $response = $this->transport->send($url, $method, $data, array('Content-Type: ' . $this->mapper->getContentType())); } catch (HttpClient_HttpStatusException $e) { $message = $e->getMessage(); if ($e->getCode() == 403 || $e->getCode() == 422) { $this->errors = $this->mapper->mapFromStorage($this->transport->getLastResponse()); if ($this->errors instanceof Error_Array && count($this->errors) > 0) { $message .= PHP_EOL . 'Errors:' . PHP_EOL . $this->errors; } } if (self::$debug) { printf('Url: %s' . PHP_EOL . 'Method: %s' . PHP_EOL . 'Data: %s', $url, $method, $data); } switch ($e->getCode()) { case 401: throw new NotLoggedInException($message, 0, $e); break; case 403: throw new ForbiddenException($message, 0, $e); break; case 404: throw new NotFoundException($message, 0, $e); break; case 406: case 422: throw new NotValidException($message, 0, $e); break; default: $message = 'Unknown error'; // no break // no break case 500: case 501: throw new ServerErrorException($message, 0, $e); break; } } return $response; }