Browse files

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:


* 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.


For more information, please see the following phplist bug report:

  • Loading branch information...
maltfield authored and samtuke committed Nov 3, 2018
1 parent 680f06d commit e01b68f83502532c752548862875751d3f0ff164
Showing with 8 additions and 0 deletions.
  1. +8 −0 public_html/lists/index.php
@@ -267,7 +267,15 @@
} else {
// we failed to subscribe the user; send an error back to
// the ajax client
echo 'FAIL';
// thow an exception so the http status code is a 500
// Internal Server Error, easily caught by jquery.ajax()
throw new Exception( "Error: Subscribe attempt failed!" );
case 'preferences':

0 comments on commit e01b68f

Please sign in to comment.