Not handling errors (from Moodle response) gracefully
Error DB error: Unknown Error (see image below) then contact does not get registered to event.
CiviCRM Version 5.78.4
Extension Version 1.2
How to replicate Enroll a civicrm contact to an event that is associated with a moodle course.
What I think is happening
I got the following Message not sent error from the Moodle response when enrolling someone in a course (presumably because email is not set up properly for my Moodle instance).
var_dumps
above the red error are values of the response and url.
Moodle receives the request to create a new user and enrol it to an associated course. It successfully both does actions (since the user is created and enroled to the right course) but the last request (which is the request asking to enrol the user to a course) returns an error saying that a message has not been successfully sent (consequently, the contact does not get enrolled in the Civi event). I think Moodle returns this error because it is not able to notify the user that they're enrolled in the course.
Civimoodle extension then receives the error but uses the civi api 3 to record a SystemLog and fails here. I'm not sure why since I tried using the GUI for civiapi 3 and it worked fine. Although I can't see that recording to the system log being a recommended logging mechanism here: https://docs.civicrm.org/dev/en/latest/framework/logging/. So, in my instance, I replaced the civiapi 3 call with Civi::log. I'm just documenting this error just in case someone experiences the same trouble in the future.