在php转换为ajax之前删除返回消息
我使用ajax调用php文件。在这个文件中,我用一个库尝试捕捉可能出现的错误 当我收到一个错误时,我用正确的消息执行die函数,但在ajax对象的success方法中,我收到一些带有错误消息的html表。我想这封信是从图书馆寄来的 可以停止或清除此返回,并发送我自己的消息吗在php转换为ajax之前删除返回消息,php,ajax,stripe-payments,Php,Ajax,Stripe Payments,我使用ajax调用php文件。在这个文件中,我用一个库尝试捕捉可能出现的错误 当我收到一个错误时,我用正确的消息执行die函数,但在ajax对象的success方法中,我收到一些带有错误消息的html表。我想这封信是从图书馆寄来的 可以停止或清除此返回,并发送我自己的消息吗 try { $card_id = $stripe->customers->createSource($stripe_account['xxxx'],['source' => $car
try {
$card_id = $stripe->customers->createSource($stripe_account['xxxx'],['source' => $card_token['id']]);
} catch (Exception $e) {
echo $e->getMessage(); //show message correctly
return "ERROR";
}
阿贾克斯:
在这种情况下,我从未得到错误字符串,只有字符串中的html表:
<br />
<font size='1'><table class='xdebug-error xe-uncaught-exception' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Fatal error: Uncaught (Status 402) (Request req_SSeWHpDt8WA4GV) The card number is not a valid credit card number.
thrown in C:\MAMP\htdocs\vendor\stripe\stripe-php\lib\Exception\ApiErrorException.php on line <i>38</i></th></tr>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Stripe\Exception\CardException: The card number is not a valid credit card number. in C:\MAMP\htdocs\vendor\stripe\stripe-php\lib\Exception\ApiErrorException.php on line <i>38</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.4018</td><td bgcolor='#eeeeec' align='right'>404976</td><td bgcolor='#eeeeec'>{main}( )</td>
(!)致命错误:未捕获(状态402)(请求请求SEWHPDT8WA4GV)卡号不是有效的信用卡号。
在第38行的C:\MAMP\htdocs\vendor\stripe\stripe php\lib\Exception\apErrorexception.php中抛出
(!)Stripe\Exception\cardeexception:卡号不是有效的信用卡号。在第38行的C:\MAMP\htdocs\vendor\stripe\stripe php\lib\Exception\apierroexception.php中
调用堆栈
#时间记忆功能定位
10.4018404976{main}()
始终以成功的ajax方法接收此数据,决不出错。错误输出来自xdebug,这是您应该在开发中安装的,而不是在生产中安装的。尽管如此,StripeAPI是个例外 以下页面显示了如何捕获它们可以抛出的各种异常: 下面是示例代码:
try {
// Use Stripe's library to make requests...
} catch(\Stripe\Exception\CardException $e) {
// Since it's a decline, \Stripe\Exception\CardException will be caught
echo 'Status is:' . $e->getHttpStatus() . '\n';
echo 'Type is:' . $e->getError()->type . '\n';
echo 'Code is:' . $e->getError()->code . '\n';
// param is '' in this case
echo 'Param is:' . $e->getError()->param . '\n';
echo 'Message is:' . $e->getError()->message . '\n';
} catch (\Stripe\Exception\RateLimitException $e) {
// Too many requests made to the API too quickly
} catch (\Stripe\Exception\InvalidRequestException $e) {
// Invalid parameters were supplied to Stripe's API
} catch (\Stripe\Exception\AuthenticationException $e) {
// Authentication with Stripe's API failed
// (maybe you changed API keys recently)
} catch (\Stripe\Exception\ApiConnectionException $e) {
// Network communication with Stripe failed
} catch (\Stripe\Exception\ApiErrorException $e) {
// Display a very generic error to the user, and maybe send
// yourself an email
} catch (Exception $e) {
// Something else happened, completely unrelated to Stripe
}
您可能没有捕获
Stripe\Exception\cardeexception
异常,请确保在类声明之前使用use Exception
,或者只需将catch(Exception$ex)
更改为catch(\Exception$ex)
,希望这能奏效。欢迎来到零食溢出,请编辑您的问题,显示您是AJAX调用,并正确格式化您的HTML块。请删除任何不必要的代码标记,以便我们更容易看到发生了什么。谢谢。谢谢!在本例中,html块是一个控制台字符串,对于这个问题并不重要。
try {
// Use Stripe's library to make requests...
} catch(\Stripe\Exception\CardException $e) {
// Since it's a decline, \Stripe\Exception\CardException will be caught
echo 'Status is:' . $e->getHttpStatus() . '\n';
echo 'Type is:' . $e->getError()->type . '\n';
echo 'Code is:' . $e->getError()->code . '\n';
// param is '' in this case
echo 'Param is:' . $e->getError()->param . '\n';
echo 'Message is:' . $e->getError()->message . '\n';
} catch (\Stripe\Exception\RateLimitException $e) {
// Too many requests made to the API too quickly
} catch (\Stripe\Exception\InvalidRequestException $e) {
// Invalid parameters were supplied to Stripe's API
} catch (\Stripe\Exception\AuthenticationException $e) {
// Authentication with Stripe's API failed
// (maybe you changed API keys recently)
} catch (\Stripe\Exception\ApiConnectionException $e) {
// Network communication with Stripe failed
} catch (\Stripe\Exception\ApiErrorException $e) {
// Display a very generic error to the user, and maybe send
// yourself an email
} catch (Exception $e) {
// Something else happened, completely unrelated to Stripe
}