Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Exception/EmptySoapResponseException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace NFePHP\Common\Exception;

class EmptySoapResponseException extends SoapException
{
public static function soapFault($message, $code)
{
return new static("Erro de comunicação "
. "via soap, $message", $code);
}
}
12 changes: 12 additions & 0 deletions src/Exception/TimeoutException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace NFePHP\Common\Exception;

class TimeoutException extends SoapException
{
public static function timeoutFault($message, $code)
{
return new static("Erro de comunicação "
. "via soap, $message", $code);
}
}
12 changes: 12 additions & 0 deletions src/Exception/UnexpectedHttpStatusException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace NFePHP\Common\Exception;

class UnexpectedHttpStatusException extends SoapException
{
public static function soapFault($message, $code)
{
return new static("Erro de comunicação "
. "via soap, $message", $code);
}
}
16 changes: 14 additions & 2 deletions src/Soap/SoapCurl.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
use NFePHP\Common\Soap\SoapBase;
use NFePHP\Common\Soap\SoapInterface;
use NFePHP\Common\Exception\SoapException;
use NFePHP\Common\Exception\TimeoutException;
use NFePHP\Common\Exception\EmptySoapResponseException;
use NFePHP\Common\Exception\UnexpectedHttpStatusException;
use NFePHP\Common\Validator;
use NFePHP\Common\Certificate;

Expand All @@ -45,6 +48,9 @@ public function __construct(Certificate $certificate = null)
* @param \SoapHeader $soapheader
* @return string
* @throws \NFePHP\Common\Exception\SoapException
* @throws \NFePHP\Common\Exception\TimeoutException
* @throws \NFePHP\Common\Exception\EmptySoapResponseException
* @throws \NFePHP\Common\Exception\UnexpectedHttpStatusException
*/
public function send(
$url,
Expand Down Expand Up @@ -130,6 +136,12 @@ public function send(
} catch (\Exception $e) {
throw SoapException::unableToLoadCurl($e->getMessage());
}
if ($this->soaperror_code === CURLE_OPERATION_TIMEDOUT) {
throw TimeoutException::timeoutFault(
"Timeout na comunicação com a SEFAZ [$url]: {$this->soaperror}",
CURLE_OPERATION_TIMEDOUT
);
}
if ($this->soaperror != '') {
if ((int)$this->soaperror_code == 0) {
$this->soaperror_code = 7;
Expand All @@ -143,10 +155,10 @@ public function send(
} elseif ((int) $httpcode == 500) {
$httpcode = 89;
}
throw SoapException::soapFault($msg, $httpcode);
throw UnexpectedHttpStatusException::soapFault($msg, $httpcode);
}
if (empty($this->responseBody)) {
throw SoapException::soapFault('Retorno da SEFAZ VAZIO', 99);
throw EmptySoapResponseException::soapFault('Retorno da SEFAZ VAZIO', 99);
}
if (!Validator::isXML($this->responseBody)) {
throw SoapException::soapFault('O retorno não é um XML ' . $this->responseBody, 99);
Expand Down