Comments (11)
@caleywoods Passing $guzzleParams['http_errors'] = false; to AvaTaxCient constructor solves this problem. example:
$guzzleParams['http_errors'] = FALSE;
$client = new Avalara\AvaTaxClient('My App', '1.0', 'development', 'sandbox', $guzzleParams);
from avatax-rest-v2-php-sdk.
You can use $client->withCatchExceptions(false);
To catch the error also
from avatax-rest-v2-php-sdk.
I tested my exact call with an online tool named Hurl.it and it looks like the API itself is doing a great job returning an HTTP 400 and the response as JSON. That can be seen in the screenshot below:
Once you step into the world of the Avalara PHP SDK / Guzzle however, this same request throws an exception as I mentioned in my first comment. I've managed to track down the cause of this.
According to the Guzzle Docs about Exceptions, HTTP level 400 response codes raise a GuzzleHttp\Exception\ClientException
if the http_errors
request option is set to true. "True" is the default setting for http_errors
. I went into the src/Client.php
file from Avalara and added:
$guzzleParams['http_errors'] = false;
To the restCall()
method as soon as the function signature is done (making it the first line of the function). This results in Guzzle no longer raising an Exception and then stops causing the Client file to stop catching that Exception and returning error strings (via $e->getMessage()
).
I am not sure that turning HTTP_ERRORS off is a great idea so I am stuck as far as having a real permanent solution. Turning them off certainly gives consumers of the API via the SDK a better experience with 4xx level errors but I did make a createTransaction
API call using the $include
param of 'ForceTimeout'
to force Avalara to respond with a 504 Gateway Timeout and with the HTTP_ERRORS turned off, no exception or issue was raised by Guzzle and I received null
when echoing out the result of a create()
call from TransactionBuilder.
from avatax-rest-v2-php-sdk.
This is a really interesting comment - I'm not sure how this slipped past. I've asked our resident PHP experts @Spadbob and @nitinshirsat to help identify whether there's a good way to improve on this. Would love suggestions!
from avatax-rest-v2-php-sdk.
Hi @caleywoods
We've implemented request events http://guzzle3.readthedocs.io/http-client/request.html#events-emitted-from-a-request and in the event handler, we are setting standard error message and response code instead of using exception. Which help us keep API error messages and codes in sync. Meaning that on an error it'll return the response with the error code and message, so no need to catch and throw extra exceptions.
from avatax-rest-v2-php-sdk.
I am having the same problem. In case of 400 errors, Guzzle is retuning a truncated... string instead of error object with errors messages. To reproduce try this code, don't add any line items:
$tb->withAddress('ShipFrom', '123 Main Street', null, null, 'Irvine', 'CA', '92615', 'US')
->withAddress('ShipTo', '100 Ravine Lane', null, null, 'Bainbridge Island', 'WA', '98110', 'US');
$result = $tb->create();
from avatax-rest-v2-php-sdk.
@ted-spence-avalara / @han8909227
I see that the catchExceptions
PR was pulled into master but I wasn't sure if master represented the current version of code available to those grabbing it via composer since I didn't see the changes listed in the most recent tag of 17.12.0-148
.
I think @khaldoonmasud problem should be fixed with #61
from avatax-rest-v2-php-sdk.
@caleywoods Yes, we deploy/tag the master branch, meaning master is the same as the most recent tag 18.5.1.208 which is on composer as well. So PR #61 should be included in the current version.
Following @khaldoonmasud 's code, I was able to replicate the string formatted error message:
Client error: POST https:\/\/sandbox-rest.avatax.com\/api\/v2\/transactions\/create resulted in a 400 Bad Request response:\n{\"error\":{\"code\":\"MissingLine\",\"message\":\"Transactions must have at least one line.\",\"target\":\"HttpRequestHeaders\",\"deta (truncated...)\n
This might need some further investigations.
from avatax-rest-v2-php-sdk.
@khaldoonmasud yes that was the workaround I ended up going with as well when I encountered the problem. I have moved on to a different job so I cannot go back and update the version of the avalara software and do any further testing.
from avatax-rest-v2-php-sdk.
That fix is good for me.
try {
// avalara request ...
$response = $tb->createOrAdjust();
} catch (\GuzzleHttp\Exception\ClientException $e) {
$error = $e->getResponse()->getBody()->getContents();
}
Example error response:
{
"error":{
"code":"ModelStateInvalid",
"message":"The request body did not contain valid JSON.",
"target":"HttpRequest",
"details":[{
"code":"JsonFormatError",
"number":47,
"message":"The request body did not contain valid JSON.",
"description":"At line 1 position 758: Unexpected character encountered while parsing value: t. Path 'createTransactionModel.discount'",
"faultCode":"Client",
"helpLink":"http://developer.avalara.com/avatax/errors/JsonFormatError",
"severity":"Error"
}]
}
}
from avatax-rest-v2-php-sdk.
This issue is fixed as part of #183. Please verify and revert if in case it is not resolved at your end.
from avatax-rest-v2-php-sdk.
Related Issues (20)
- PHP 8 Support HOT 9
- How to CreateCustomers in PHP SDK HOT 1
- how to resolve Address result HOT 1
- Refund Transaction creates transaction with all zero amounts HOT 3
- Timeout Hardcoded HOT 2
- How do I specify a unit for parameters that accept units? HOT 2
- Magento 2.4.4 setup:di:compile error for lib 23.6.0 HOT 3
- downloadTaxRatesByZipCode endpoint fails with unexpected format HOT 1
- How to handling error? HOT 1
- Avalara\AvaTaxClient" not found
- How to omit tax codes in transactions HOT 2
- Address model cannot be set with locationCode HOT 1
- Keep SDK version in constant and use it across requests HOT 2
- During Composer install, AvaTaxClientBase not passing in params needed to load HOT 2
- File has mixed line endings; this may cause incorrect results HOT 1
- AvaTaxClient methods no longer returning API JSON error message for HTTP 4** etc responses. HOT 1
- Transactions are not being reported in real-time in the dashboard HOT 1
- Try/catch is not firing on exception and server is responding with 502 error for transaction with invalid addresses HOT 1
- Missing method to set $this->_model['email '] (Customer Email) HOT 1
- commitTransaction method not behaving as expected, has incorrect inline documentation HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from avatax-rest-v2-php-sdk.