Skip to content

Commit

Permalink
fix: Avoids sending invalid JSON to the LRS. (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
garemoko authored and ryasmi committed Dec 21, 2018
1 parent ca9a506 commit 29ae19b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/loader/lrs.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ function load(array $config, array $events) {
$auth = base64_encode($username.':'.$password);
$postdata = json_encode($statements);

if ($postdata === false) {
throw new \Exception('JSON encode error: '.json_last_error_msg());
}

$request = curl_init();
curl_setopt($request, CURLOPT_URL, $url);
curl_setopt($request, CURLOPT_POSTFIELDS, $postdata);
Expand Down
4 changes: 4 additions & 0 deletions src/loader/moodle_curl_lrs.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ function load(array $config, array $events) {
$auth = base64_encode($username.':'.$password);
$postdata = json_encode($statements);

if ($postdata === false) {
throw new \Exception('JSON encode error: '.json_last_error_msg());
}

$request = new \curl();
$responsetext = $request->post($url, $postdata, [
'CURLOPT_HTTPHEADER' => [
Expand Down

0 comments on commit 29ae19b

Please sign in to comment.