stopOnError 和 continueOnError 标志指示如果当前请求中发生错误,当前请求的剩余部分要做什么(停止或继续)。
例如,如果您这样做:
<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="2.0"?>
<QBXML>
<QBXMLMsgsRq onError="continueOnError">
<CustomerAddRq requestID="1">
...
</CustomerAddRq>
<InvoiceAddRq requestID="2">
...
</InvoiceAddRq>
....
您告诉 QuickBooks,如果在 CustomerAddRq 部分发生错误,请忽略它并继续处理 InvoiceAddRq 部分(与如果您使用 stopOnError 相比,它甚至不会在遇到 InvoiceAddRq 后尝试CustomerAddRq 部分出错。
但是,如果您正确使用了 Web 连接器(您是正确的),那么您将发送多个单独的请求,而不是像上面示例中那样发送一个批处理请求。这意味着 stopOnError 和 continueOnError 不是您需要的。
相反,您需要使用错误处理程序来处理 PHP 代码中的错误。
添加功能:
/**
* Try to handle an error
*
* @param string $requestID
* @param string $user This is the username of the connected Web Connector user
* @param string $action The action type that experienced an error (i.e. QUICKBOOKS_ADD_CUSTOMER, or QUICKBOOKS_QUERY_CUSTOMER, or etc.)
* @param string $ID The $ID value of the record that experienced an error (usually your primary key for this record)
* @param array $extra
* @param string $err If an error occurs **within the error handler**, put an error message here (i.e. if your error handler experienced an internal error), otherwise, leave this NULL
* @param string $xml
* @param string $errnum The error number or error code which occurred
* @param string $errmsg The error message received from QuickBooks
* @return boolean Return TRUE if the error was handled and you want to continue processing records, or FALSE otherwise
*/
function my_error_handler($requestID, $user, $action, $ID, $extra, &$err, $xml, $errnum, $errmsg)
{
// ...
// return true; // return TRUE if you want the Web Connector to continue to process requests
// return false; // return FALSE if you want the Web Connector to stop processing requests and report the error
}
并确保将新的错误处理函数告诉 QuickBooks PHP 库:
$errmap = array(
// This is an array mapping the error number/code to the error handler function
3070 => 'my_error_handler',
// You can also use static method error handlers if you don't like functions...
// 3070 => 'MyStaticClass::myStaticMethod',
// ... or object instant error handlers.
// 3070 => array( $MyObjectInstance, 'myMethod' ),
// You can also register a "catch-all" error handler to catch all errors:
// '*' => 'my_catchall_error_handler',
);
更多信息: