我用ajax调用php文件。在这个文件中,我尝试了一个库,以获取可能的错误。
当我收到错误时,我用正确的消息执行die函数,但是在ajax对象的成功方法中,我收到了一些带有错误消息的html表。我觉得这条消息来自图书馆。
这是可能的止损或清除此回报,然后发送我自己的消息?
try {
$card_id = $stripe->customers->createSource($stripe_account['xxxx'],['source' => $card_token['id']]);
} catch (Exception $e) {
echo $e->getMessage(); //show message correctly
return "ERROR";
}
Ajax:
$.ajax({
url: '/intranet/pms/includes/pay.php',
type: 'POST',
data: payment,
beforeSend: () => {
},
success: function(data){
console.log(data)
},
error: function (jqXHR, exception) {
console.log("ERROR")
}
});
在这种情况下,我永远不会得到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>
总是以成功的ajax方法接收此数据,永远不会出错。
答案 0 :(得分:0)
该错误输出来自xdebug,这应该在开发中安装,而不是在生产中安装。话虽如此,该异常位于Stripe Api中。
以下页面显示了如何捕获它们可能引发的各种异常:https://stripe.com/docs/api/errors/handling
这实际上是示例代码:
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
}
答案 1 :(得分:0)
您可能没有捕获到function popChoice_Callback(hObject, eventdata, handles)
contents = cellstr(get(hObject,'String'));
popChoice = contents(get(hObject,'Value'));
if (strcmp(popChoice,'Sine'))
popVal = 1;
elseif (strcmp(popChoice,'Square'))
popVal = 2;
elseif (strcmp(popChoice,'Sawtooth'))
popVal = 3;
elseif (strcmp(popChoice,'Triangular'))
popVal = 4;
end
assignin('base','popVal',popVal)
updateAll()
%%Some other unrelated coder (sliders, etc) is between these functions
function updateAll
f=round(getappdata(0,'f'));
S_rate=round(getappdata(0,'S_rate'));
t=round(getappdata(0,'t'));
phi=round(getappdata(0,'phi'));
popVal = getappdata(0,'popVal');
if popVal == 1
Sin_Wave(f,phi,S_rate,t)
elseif popVal == 2
Square_Wave(f,phi,S_rate,t)
elseif popVal == 3
Sawtooth_Wave(f,phi,S_rate,t)
elseif popVal == 4
Triangle_Wave(f,phi,S_rate,t)
end
异常,请确保在类声明之前使用Stripe\Exception\CardException
,或者只是将use Exception
更改为catch(Exception $ex)
,希望这可以起作用