Skip to content

Commit e01b68f

Browse files
maltfieldSam Tuke
authored andcommitted
return error code on FAIL in ajax subscribe (#432)
* Adding (more) graceful failure when phplist does not have access to random_bytes() from some cryptographically secure pseudorandom number generator (CSPRNG). For more info, please see: * https://discuss.phplist.org/t/common-installation-errors-manual-chapter-feedback-and-discussion/217/4 * https://mantis.phplist.org/view.php?id=18546 * https://tech.michaelaltfield.net/2018/08/25/fix-phplist-500-error-due-to-random_compat/ * Added a line to throw an exception when the phplist ajax subscribe endpoint fails to add a new subscriber. Throwing this exception causes php to return a 500 Internal Server Error, rather than the existing functionality which just returns a 200 error (merely containing 'FAIL' in the body of the response). Consequently, the ajax client thinks the failure is actually a success, since the http status code is still a 200. This change makes the response more robust and easier for ajax clients (such as the jquery example linked below) to catch errors from phplist. * https://discuss.phplist.org/t/ajax-subscribe-api/974 For more information, please see the following phplist bug report: * https://mantis.phplist.org/view.php?id=19524
1 parent 680f06d commit e01b68f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

public_html/lists/index.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,15 @@
267267
}
268268
exit;
269269
} else {
270+
// we failed to subscribe the user; send an error back to
271+
// the ajax client
272+
270273
echo 'FAIL';
274+
275+
// thow an exception so the http status code is a 500
276+
// Internal Server Error, easily caught by jquery.ajax()
277+
throw new Exception( "Error: Subscribe attempt failed!" );
278+
271279
}
272280
break;
273281
case 'preferences':

0 commit comments

Comments
 (0)