Skip to content

Commit

Permalink
Handle exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
psrpinto committed Feb 15, 2024
1 parent cb926b5 commit 7a09131
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions includes/class-wporg-gp-translation-events-route.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ public function __construct() {
* @return void
*/
public function events_list() {
$current_datetime_utc = ( new DateTime( 'now', new DateTimeZone( 'UTC' ) ) )->format( 'Y-m-d H:i:s' );
$current_datetime_utc = null;
try {
$current_datetime_utc = ( new DateTime( 'now', new DateTimeZone( 'UTC' ) ) )->format( 'Y-m-d H:i:s' );
} catch ( Exception $e ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
error_log( $e );
$this->die_with_error( 'Something is wrong.' );
}

$_current_events_paged = 1;
$_upcoming_events_paged = 1;

Expand Down Expand Up @@ -135,12 +143,20 @@ public function events_edit( int $event_id ) {
$css_show_url = '';
$event_title = $event->post_title;
$event_description = $event->post_content;
$event_timezone = get_post_meta( $event_id, '_event_timezone', true ) ?: '';
$event_start = self::convertToTimezone( get_post_meta( $event_id, '_event_start', true ), $event_timezone ) ?? '';
$event_end = self::convertToTimezone( get_post_meta( $event_id, '_event_end', true ), $event_timezone ) ?? '';
$event_status = $event->post_status;
list( $permalink, $post_name ) = get_sample_permalink( $event_id );
$permalink = str_replace( '%pagename%', $post_name, $permalink );
$event_timezone = get_post_meta( $event_id, '_event_timezone', true ) ?: '';

try {
$event_start = self::convertToTimezone( get_post_meta( $event_id, '_event_start', true ), $event_timezone ) ?? '';
$event_end = self::convertToTimezone( get_post_meta( $event_id, '_event_end', true ), $event_timezone ) ?? '';
} catch ( Exception $e ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
error_log( $e );
$this->die_with_error( 'Something is wrong.' );
}

$this->tmpl( 'events-form', get_defined_vars() );
}

Expand Down

0 comments on commit 7a09131

Please sign in to comment.