Bug Report on REST V2 PHP API - Json Error Return truncated

  • 2
  • Problem
  • Updated 2 months ago
The PHP API uses GuzzleHTTP for generating the transport in communicating with the Avalara server. What I found was, that Guzzle, when it does exception processing for a non 200 return, truncates the returned error message from the avalara server at 120 characters, intentionally. This breaks the json that the server is attempting to return and it's not possible to get the detail on the error. Additionally, the Avalara try/catch block, doesn't return the truncated buffer as an object, but instead as a string, so even if I hack the 120 characters in guzzle to something that would accommodate the full json return, it still would be mangled. 

 I worked around this by parsing the string I do get back and pulling the general error message out to return to the user (because that is toward the beginning of the would be json return), but I think it would work more as Avalara intended, if the HTTP error message was not throwing an exception (and not truncating what information it returned). It appears to me that the Avalara routine wanted the HTTP error returned in the same manner a 200 was returned and expected it, so the json would be returned as the object rather than the string. 

If this is of interest, I have all the filenames and line numbers where this is happening. I don't have a problem with it because I have a workaround. In fact, if it were fixed, my code will break.

This is on PHP 7.2, GuzzleHTTP, and Apache. Aside from this, the PHP API is working great.
Photo of Chris

Chris

  • 5 Posts
  • 0 Reply Likes

Posted 11 months ago

  • 2
Photo of Martha Dudley

Martha Dudley

  • 1 Post
  • 0 Reply Likes
I am new to Avalara and have been entering all sorts of incorrect data to see what the response looks like.  I have also received a truncated string as a response rather than an object.  Is there another way to deal with this other than parsing the string?
Photo of Chris Pratt

Chris Pratt

  • 1 Post
  • 0 Reply Likes
You would have to hack Guzzle and correct their issue by increasing the buffer size. This would make updates a problem later. I chose to parse the string directly because it would have no impact on 3rd party Avalara and Guzzle code. I use a gettype($t) (where $t is the return from Avalara code) and check if it's equal to "object". If it is, the json can be handled normally as a PHP array, if it's not, you have to parse it as a string and dig out the error.