When an API call does not return success, the error message is printed to the screen (in a rather ugly fashion) unless Drupal's core error level outright prevents it.
Example:
Authorize.net AIM AuthorizeNet Error: Response Code: 3 Response Subcode: 1 Response Reason Code: 6 Response Reason Text: The credit card number is invalid.
For my use case, I want to return a human-readable response (which is contained in the error message above and the API response object), but since the module prints the above error message any time messages are enabled, all I can do is add a second message, not prevent the one above.
The code in question is in authnet.module in the authnet_log_response() function:
// Process the message if it's an error, or if debug mode is on.
if (!$status['success'] || variable_get('authnet_debug', FALSE)) {
// Print errors to the screen, if Drupal's core error_level variable is greater than or equal to 1.
if (!$status['success'] && variable_get('error_level', 1) >= 1) {
drupal_set_message($status['message'], 'error');
}
// Log the message to watchdog.
watchdog('authnet', $status['message']);
}
I would argue that the error message shouldn't be sent to the browser (at least in its current incarnation) by default. Instead it should only be shown if debug mode is on. This would allow the programmer to display whatever message works best for the use case.
I'll submit a patch shortly.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | authnet.error_messages_debug_only-2128433-1.patch | 798 bytes | rkeppner |
Comments
Comment #1
rkeppner commentedComment #2
rkeppner commentedThe attached patch essentially just disables sending the error message to the browser unless the authnet debug mode is on.
My thought behind this is that if debug is on, all of those codes might just be useful, otherwise, probably not. This also leaves the programmer free to display messages as desired, rather than having to disable Drupal messages entirely if he wishes to keep the site user from seeing an ugly and possibly confusing error message.
Comment #3
m.stentaMakes sense to me. Committed to both 7.x and 6.x branches!