Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

- TMS-1183: Use Logger for EventzClient errors

## [1.62.0] - 2025-06-23

- TMS-1172: Add video possibility to hero-museum layout
Expand Down
6 changes: 4 additions & 2 deletions lib/EventzClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,12 @@ public function do_get_request( string $api_url = '' ) {
$status_code = $payload->status_code;

if ( ! in_array( $status_code, [ 200, 201 ], true ) ) {
throw new EventzException(
( new Logger() )->error(
sprintf( '%s: %s', $api_url, $payload->body ?? 'Unknown error' ),
$status_code
[ 'status_code' => $status_code ]
);

return false;
Comment on lines +319 to +324

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This change from throwing an exception to returning false is a breaking change in the function's contract. It can lead to new fatal errors in downstream code that is not prepared to handle a false value.

For example, lib/Eventz.php's admin_event_search_callback() calls $client->search_events() and then accesses $events->items. If search_events() propagates this false value, the code will crash with a "Trying to get property 'items' of non-object" fatal error.

While preventing uncaught exceptions is the right goal, this solution trades one fatal error for another. A safer approach is to handle errors inside the specific EventzClient methods (like search_events and get_item). These methods have the context to return a sensible default (e.g., an empty result set or null) that won't break their callers. I recommend handling the error in the higher-level methods of EventzClient to provide safe defaults to consumers.

}

return $payload->body ?? '';
Expand Down
Loading