Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Meetup Client: Handle Errors better #564

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions mu-plugins/utilities/class-meetup-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,10 @@ public function get_groups( array $args = array() ) {

$result = $this->send_paginated_request( $query, $variables );

if ( is_wp_error( $result ) || ! array_key_exists( 'groupsSearch', $result['proNetworkByUrlname'] ) ) {
if ( is_wp_error( $result ) ) {
return $result;
} elseif ( empty( $result['proNetworkByUrlname'] ) ) {
return new WP_Error( 'not_found', 'Invalid API response.' );
}

$groups = array_column(
Expand Down Expand Up @@ -588,15 +590,13 @@ public function get_event_details( $event_id ) {

$result = $this->send_paginated_request( $query, $variables );

if ( is_wp_error( $result ) || ! array_key_exists( 'event', $result ) ) {
if ( is_wp_error( $result ) ) {
return $result;
} elseif ( empty( $result['event'] ) ) {
return false;
}

$event = $result['event'] ?: false;

if ( $event ) {
$event = $this->apply_backcompat_fields( 'event', $event );
}
$event = $this->apply_backcompat_fields( 'event', $result['event'] );

return $event;
}
Expand Down Expand Up @@ -693,8 +693,10 @@ public function get_group_details( $group_slug, $args = array() ) {

$result = $this->send_paginated_request( $query, $variables );

if ( is_wp_error( $result ) || ! isset( $result['groupByUrlname'] ) ) {
if ( is_wp_error( $result ) ) {
return $result;
} elseif ( empty( $result['groupByUrlname'] ) ) {
return new WP_Error( 'not_found', 'Invalid API response.' );
}

// Format it similar to previous response payload.
Expand Down Expand Up @@ -755,8 +757,10 @@ public function get_group_members( $group_slug, $args = array() ) {
);

$results = $this->send_paginated_request( $query, $variables );
if ( is_wp_error( $results ) || ! isset( $results['groupByUrlname'] ) ) {
if ( is_wp_error( $results ) ) {
return $results;
} elseif ( empty( $results['groupByUrlname'] ) ) {
return new WP_Error( 'not_found', 'Invalid API response.' );
}

// Select memberships.edges[*].node.
Expand Down Expand Up @@ -830,11 +834,9 @@ public function get_network_events( array $args = array() ) {

$results = $this->send_paginated_request( $query, $variables );

if ( is_wp_error( $results ) || ! array_key_exists( 'eventsSearch', $results['proNetworkByUrlname'] ) ) {
if ( is_wp_error( $results ) ) {
return $results;
}

if ( empty( $results['proNetworkByUrlname']['eventsSearch'] ) ) {
} elseif ( empty( $results['proNetworkByUrlname']['eventsSearch'] ) ) {
return array();
}

Expand Down Expand Up @@ -953,8 +955,10 @@ function( $a, $b ) {
);

$results = $this->send_paginated_request( $query, $variables );
if ( is_wp_error( $results ) || ! isset( $results['groupByUrlname'] ) ) {
if ( is_wp_error( $results ) ) {
return $results;
} elseif ( empty( $results['groupByUrlname'] ) ) {
return new WP_Error( 'not_found', 'Invalid API response.' );
}

// Select {$event_field}.edges[*].node.
Expand Down Expand Up @@ -1029,7 +1033,7 @@ public function get_result_count( $route, array $args = array() ) {
return $results;
}

return (int) $results['proNetworkByUrlname']['groupsSearch']['count'];
return (int) $results['proNetworkByUrlname']['groupsSearch']['count'] ?? 0;
}

/**
Expand Down
Loading