diff --git a/includes/class-participad-client.php b/includes/class-participad-client.php index c412481..a159310 100644 --- a/includes/class-participad-client.php +++ b/includes/class-participad-client.php @@ -54,10 +54,14 @@ protected function call( $function, array $arguments = array() ) { throw $e; } + if ( 200 !== $request['response']['code'] ) { + throw new UnexpectedValueException( "Unknown error: " . $request['response']['code'] ); + } + $result = json_decode( $request['body'] ); if ( $result === null ) { - throw new UnexpectedValueException("JSON response could not be decoded"); + throw new UnexpectedValueException( "JSON response could not be decoded" ); } return $this->handleResult($result); diff --git a/includes/class-participad-post.php b/includes/class-participad-post.php index 5651b6d..121bf1a 100644 --- a/includes/class-participad-post.php +++ b/includes/class-participad-post.php @@ -115,7 +115,24 @@ public static function create_ep_post( $wp_post_id, $ep_post_group_id ) { $ep_post = participad_client()->createGroupPad( $ep_post_group_id, $ep_post_id, $wp_post_content ); $pad_created = true; } catch ( Exception $e ) { - $ep_post_id = self::generate_random_name(); + + $error_message = $e->getMessage(); + $error_code = substr( $error_message, strrpos( $error_message, ':' ) + 2 ); + + switch ( $error_code ) { + + // Request URI too long + // @see https://github.com/boonebgorges/participad/issues/23 + case '414' : + return new WP_Error( 'create_ep_post', __( 'Could not create the Etherpad Lite post', 'participad' ) ); + break; + + // Assume that there's a conflict, and try again + default : + $ep_post_id = self::generate_random_name(); + break; + + } } }