Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

get_response() could be more verbose with errors #127

Closed
patrickmj opened this issue Oct 12, 2018 · 0 comments
Closed

get_response() could be more verbose with errors #127

patrickmj opened this issue Oct 12, 2018 · 0 comments
Assignees

Comments

@patrickmj
Copy link
Member

patrickmj commented Oct 12, 2018

The minimal thing to do is to change

// if it returns a 403 it will return no $output
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
$output = curl_exec($ch);

to turn FAILONERROR off. But that will entail significant changes to the functions that use get_response() so that they can respond to whatever gets passed back to them. Or, some additional work just within that function to log details about the error and pass back a generic error message.

This came up trying to debug an empty response from DPLA in these lines

    $data = get_response($url);
    $json = json_decode($data);
    
    if (isset($json->error)) {
      wp_send_json(json_encode( "There was an error: " . $json->error));
      wp_die();
      return;
    }

Because get_response() returns nothing on a 403, the error handling never kicked in, since json_decode() barfed on the empty $data.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant