I am using Paypal-PHP. SDK, a I want to get code errors. When I put wrong credit card data, I am getting this JSON as answer:
{
"name":"CREDIT_CARD_REFUSED",
"message":"Credit card was refused",
"information_link":"https://developer.paypal.com/webapps/developer/docs/api /#CREDIT_CARD_REFUSED",
"debug_id":"63a9cf220d272"
}
or this:
{"name":"VALIDATION_ERROR",
"details":[
{"field":"payer.funding_instruments[0].credit_card.expire_month","issue":"Must not be blank"},
{"field":"payer.funding_instruments[0].credit_card.expire_year","issue":"Must not be blank"},
{"field":"payer.funding_instruments[0].credit_card.cvv2","issue":"Must be numeric"}],
"message":"Invalid request - see details","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#VALIDATION_ERROR","debug_id":"8e61a15a1bf4a"}
But I need error code. How Can I get it?
Thanks
REST API usually do not return error codes like classic API. There are no error codes associated with the error message.
It just returns the error object with name debug_id message information_link details
Related
I am trying to bring photos from Zenfolio database using PHP. I keep receiving this error
Zenfolio API Error for method LoadGroupHierarchy: E_NOSUCHOBJECT (Error Code: 90009)
I am using admin username and password. Any ideas why?
Currently I'm working with the yodlee API. As specified in the documentation the url response may throw InvalidCredentails or UserAccountLocked. I'm using PHP and I get the following response when the username or password is incorrect.
{
Error: [
{
errorDetail: "Invalid Cobrand Credentials"
}
]
}
So to check if the error occurs I want to write some code that checks if errorDetail has a value of Invalid Cobrand Credentials.
So far ok.
But the there may be so many types of errors, and each error name is different. My question is: Can I get the list of these errorDetail values
so that I can make it work without checking if the code is forcebly throwing the errors.
You can just check for the Error index and access it's value for throwing the errors. Something like this should work for you (not tested). From the repo page:
yodleeAPI.getAccounts(accessToken)
.then(function(response) {})
.catch(function(error) {});
Edit:
As far as I could tell there wasn't any exception list. So you're either going to have to go through all the exceptions manually or create a generic error message for users. I would just advice to catch the exception message and use that for the user view(if there isn't any security information in there). You can accomplish that by following the above code.
If you do feel the need to go through every exception yourself I managed to at least get the list of all methods that throw exceptions (search: exception). You'll have to go through it yourself, and parse the error message yourself. But you can find that here
I am using the Facebook PHP SDK V3.2.3 and have built a web based app which simply gets users albums and pics and displays them on our site after the user authorises themselves.
I have tested the site functionality on different machines on different browsers/networks and everything works as expected from our side. We can authorise as the developers set on the account as well as the test user and authorise and see the pics/albums, problem free.
I submitted the app for review and it was denied - these are the notes returned.
When I click on the Facebook button, I receive the following error message,
" Fatal error: Uncaught GraphMethodException: Unsupported get request. thrown in
/home/websitename/public_html/sitedir/src/base_facebook.php
on line 1325."
Has anybody else had this issue? I am am completely at a loss as I can't debug this as I cannot recreate the problem.
It looks like you are trying to access something in your code that you do not have access to, or something that doesn't exist.
You should always wrap your Facebook API code in try...catch statements to catch any issues and fail gracefully.
try {
// some Facebook API call
} catch ( Exception $e ) {
// an error occurred
echo $e->getMessage();
}
I am creating custom class to throw a error from zend as there is not built-in mechanism for this in zend. I am able to give proper response to the user. But I am having problem in returning status code for this.
$obj = $this->toJsonModel($result);
$this->getResponse()->setStatusCode(403);
error_log('Status Code' . $this->getResponse()->getStatusCode());
return $obj;
I am getting response in $obj in Json format. Then I am setting status code to 403 for this API which I created. And then I am returning $obj from this controller.
But I am not getting 403 error when I tried this code. It's always showing 200 as a status code.
Some other code was causing a problem in executing this and was giving 200 every time but when I re-did some, it started working.
Should I rely on http status codes? Or should I use some kind of special response?
My server is running PHP and producing simple JSON responses.
I'd personally say you should do both! Return an appropriate 4xx/5xx status code to show something went wrong and include a message into your JSON response.
E.g. for a successful request:
{
"success": "true"
}
And for fail (e.g. 405 Method not allowed):
{
"success": "false",
"message": "Requested data not available"
}
It could be better if , you can go with an Entity with Two Properties as : Status & Message.
You inherit your query result entity from the above entity.
If the operation is successful then Set the Status to True else set Status to False and set appropriate error message into the Message property of above entity.
Remember that it is better you don't put exact database errors into the client side displays. That may increase the chances of hacking attacks, instead you can log the exact message on the server so that the concerned people can check the messages, if something goes wrong.
So, if Status=True then only the client can further process the message (like accessing the properties or displaying them etc.), else if Status=False, then the error text set at the data access logic, into the Message property will be displayed.