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

Add details to error messages to make them more helpful #372

Merged
merged 1 commit into from
Oct 2, 2018

Conversation

aaron-junot
Copy link

When an error comes back from the server, it has a details tag in the XML. For example:

<?xml version="1.0" encoding="UTF-8"?>
<error>
<symbol>invalid_xml</symbol>
<description>The provided XML was invalid.</description>
<details>Unacceptable tags &lt;address&gt;</details>
</error>

Just stating that the provided XML was invalid is rather useless to a developer trying to fix their issues. Adding the detail of the unacceptable tag is much better.

This issue was originally highlighted by #344, which shows an example of where a developer would have been able to fix their issue more easily if they could see the details of the error.


public function __toString() {
if (!empty($this->field) && ($this->__readableField() != 'base')) {
return $this->__readableField() . ' ' . $this->description;
$details = $this->details ? ' Details: ' .$this->details : '';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit but space after the period?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, that was my bad. Fixed

@@ -57,7 +57,8 @@ public function assertValidResponse()
case 0:
throw new Recurly_ConnectionError('An error occurred while connecting to Recurly.');
case 400:
$message = (is_null($error) ? 'Bad API Request' : $error->description);
$details = $this->details ? ' Details: ' .$this->details : '';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems odd to be referencing $this rather than $error? Though in either case if it runs through parseErrorXml I'd expect an error object to come back and that we could use the interpolated value in $error->message. How were you testing this out?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you were right, that was supposed to be $error rather than $this in that context

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, there is no unit test for this change. I'll add a test in the Tests directory.

Copy link
Contributor

@bhelx bhelx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@aaron-junot
Copy link
Author

aaron-junot commented Oct 2, 2018

@drewish I added a test to show that the <details> tag successfully gets appended to the message accessible by $e->getMessage()

Copy link

@drewish drewish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@bhelx bhelx merged commit 9198e34 into master Oct 2, 2018
@bhelx bhelx deleted the aaron-suarez/add-details-tag branch October 2, 2018 23:05
@bhelx bhelx added the V2 V2 Client label Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
V2 V2 Client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants