Skip to content

Commit

Permalink
Merge pull request #7 from Escavador/fix_exception_messages
Browse files Browse the repository at this point in the history
Add previous exception message when existing
  • Loading branch information
gabrielpeixoto authored Jul 14, 2021
2 parents 93dee5d + 9630171 commit d6ed0ed
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/Exception/VespaException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class VespaException extends \Exception
{
public function __construct($message, \Exception $exception = null)
{
parent::__construct($message, 001, $exception);
$previous_message = $exception ? "\n{$exception->getMessage()}" : "";

parent::__construct("{$message}{$previous_message}", 001, $exception);
}
}
6 changes: 4 additions & 2 deletions src/Exception/VespaExecuteJobException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ class VespaExecuteJobException extends VespaException

public function __construct(string $job_class, string $document_type, \Exception $exception = null, string $message = null)
{
$previous_message = $exception ? "\n{$exception->getMessage()}" : "";

if (!$message) {
parent::__construct("[{$document_type}] The job $job_class process failed", $exception);
parent::__construct("[{$document_type}] The job $job_class process failed.$previous_message", $exception);
} else {
parent::__construct("[{$document_type}] $job_class - $message", $exception);
parent::__construct("[{$document_type}] $job_class - $message$previous_message", $exception);
}

$this->code = 600;
Expand Down
4 changes: 3 additions & 1 deletion src/Exception/VespaFailDeleteDocumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ class VespaFailDeleteDocumentException extends VespaException

public function __construct($definition, string $scheme, \Exception $exception = null)
{
parent::__construct("[{$definition->getDocumentType()}]: An error occurred while deleting the document to the scheme : $scheme.", $exception);
$previous_message = $exception ? " {$exception->getMessage()}" : "";

parent::__construct("[{$definition->getDocumentType()}]: An error occurred while deleting the document to the scheme : $scheme.$previous_message", $exception);

$this->code = 100;
$this->definition = $definition;
Expand Down
4 changes: 3 additions & 1 deletion src/Exception/VespaFailGetDocumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class VespaFailGetDocumentException extends VespaException

public function __construct(DocumentDefinition $definition, string $scheme, \Exception $exception)
{
parent::__construct("[{$definition->getDocumentType()}]: An error occurred while getting the document to the scheme: $scheme", $exception);
$previous_message = $exception ? " {$exception->getMessage()}" : "";

parent::__construct("[{$definition->getDocumentType()}]: An error occurred while getting the document to the scheme: $scheme.$previous_message", $exception);

$this->code = $exception->getCode();
$this->definition = $definition;
Expand Down
4 changes: 3 additions & 1 deletion src/Exception/VespaFailSearchException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ class VespaFailSearchException extends VespaException

public function __construct(array $data, \Exception $exception = null)
{
parent::__construct("An error occurred while performing the search on Vespa. Payload: " . json_encode($data), $exception);
$previous_message = $exception ? "\n{$exception->getMessage()}" : "";

parent::__construct("An error occurred while performing the search on Vespa. Payload: " . json_encode($data) . $previous_message, $exception);

$this->code = 300;
$this->payload = $data;
Expand Down
4 changes: 3 additions & 1 deletion src/Exception/VespaFailSendDocumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class VespaFailSendDocumentException extends VespaException

public function __construct(DocumentDefinition $definition, AbstractDocument $document, \Exception $exception = null)
{
parent::__construct("[{$definition->getDocumentType()}]: Document {$document->getVespaDocumentId()} was not indexed to Vespa.", $exception);
$previous_message = $exception ? " {$exception->getMessage()}" : "";

parent::__construct("[{$definition->getDocumentType()}]: Document {$document->getVespaDocumentId()} was not indexed to Vespa.{$previous_message}", $exception);

$this->code = 400;
$this->document = $document;
Expand Down
4 changes: 3 additions & 1 deletion src/Exception/VespaFailUpdateDocumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class VespaFailUpdateDocumentException extends VespaException

public function __construct(DocumentDefinition $definition, AbstractDocument $document, \Exception $exception = null)
{
parent::__construct("[{$definition->getDocumentType()}]: Document {$document->getVespaDocumentId()} was not updated to Vespa.", $exception);
$previous_message = $exception ? " {$exception->getMessage()}" : "";

parent::__construct("[{$definition->getDocumentType()}]: Document {$document->getVespaDocumentId()} was not updated to Vespa.$previous_message", $exception);

$this->code = 500;
$this->document = $document;
Expand Down
6 changes: 4 additions & 2 deletions src/Exception/VespaFeedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ class VespaFeedException extends VespaException

public function __construct(string $model, \Exception $exception = null, string $message = null)
{
$previous_message = $exception ? "\n{$exception->getMessage()}" : "";

if (!$message) {
parent::__construct("[{$model}] Feed process failed", $exception);
parent::__construct("[{$model}] Feed process failed.$previous_message", $exception);
} else {
parent::__construct("[{$model}] $message", $exception);
parent::__construct("[{$model}] $message$previous_message", $exception);
}

$this->code = 600;
Expand Down
4 changes: 3 additions & 1 deletion src/Exception/VespaInvalidHostException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ class VespaInvalidHostException extends VespaException
{
public function __construct(\Exception $exception = null)
{
parent::__construct("Invalid Vespa Host", $exception);
$previous_message = $exception ? " {$exception->getMessage()}" : "";

parent::__construct("Invalid Vespa Host.$previous_message", $exception);

$this->code = 700;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Exception/VespaInvalidYQLQueryException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ class VespaInvalidYQLQueryException extends VespaException
{
public function __construct($message = null, \Exception $exception = null)
{
$previous_message = $exception ? "\n{$exception->getMessage()}" : "";

if ($message != null) {
$message = " $message";
}
parent::__construct("Could not instantiate query from YQL.$message", $exception);
parent::__construct("Could not instantiate query from YQL.$message${previous_message}", $exception);

$this->code = 800;
}
Expand Down

0 comments on commit d6ed0ed

Please sign in to comment.