Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When an exception is thrown, the original message gets lost. #80

Closed
razvan-tache opened this issue Jan 15, 2018 · 0 comments
Closed

When an exception is thrown, the original message gets lost. #80

razvan-tache opened this issue Jan 15, 2018 · 0 comments

Comments

@razvan-tache
Copy link

When a request towards PayU is made, if invalid, a proper http response message will be returned from payu specifying why the message failed.

The way the response if verified is by throwing an exception if an invalid http status is received.

OpenPayU_Http::throwHttpStatusException($httpStatus, $result);

If the issue was with the request data an OpenPayu_Exception will be thrown:

throw new OpenPayU_Exception($message->getStatus().' - '.$statusDesc, $statusCode);

But the OpenPayuException doesn't receive further the response message which may contain usefull data, therefore losing that data for the final user.

My proposal is that of a new type of exception:

class OpenPayU_Exception_Request extends OpenPayU_Exception
{
    private $response;

    public function __construct($response, $message = "", $code = 0, Throwable $previous = null)
   {
        $this->response = $response;
        parent::_construct($message, $code, $previous);
    }

    public function getResponse()
    {
          return $this->response;
    }
}

And when building the exception:

case 400:
    throw new OpenPayU_Exception_Request($message, $message->getStatus().' - '.$statusDesc, $statusCode);
    break;

This will also ensure backwards compatibility as the core of: OpenPayu_Exception($message->getStatus().' - '.$statusDesc, $statusCode) is stil built by the parent::__construct call

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants