Skip to content

Handle Frost Errors #2

@lautarodragan

Description

@lautarodragan

The Po.et Plugin currently ignores any type of errors that could happen when submitting a work to the Frost API.

$consumer = new Consumer( $author, $url, $token, $post );
//Posting the article to the API
try {
$response = $consumer->consume();
$decoded_response_body = json_decode( $response['body'] );
//Adding initial empty meta key for the poet work id
update_post_meta( $post_id, 'poet_work_id', '' );
//Checking if the returned response body is a valid JSON string
if ( json_last_error() !== JSON_ERROR_SYNTAX
&& is_object( $decoded_response_body )
&& property_exists( $decoded_response_body, 'workId' ) ) {
//Creating or updating poet work id meta to the returned work id
update_post_meta( $post_id, 'poet_work_id', $decoded_response_body->workId );
}
} catch ( Exception $exception ) {
}
}

The catch block is empty, and the if ( json_last_error() !== JSON_ERROR_SYNTAX ... doesn't have an else.

Any error that might prevent the article from actually being persisted by Frost should be both communicated to the user and preserved in a log.

TBD
Proper UI and UX for these error messages

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions