From c8e06b98aa9ffbfc155b5862ee6f4941c55a56dc Mon Sep 17 00:00:00 2001 From: Mia Bennett Date: Tue, 18 Jun 2024 14:56:06 +0930 Subject: [PATCH 1/4] fix(events): [PPT-1390] return 404 instead of 500 if the event can't be found upstream. --- src/controllers/events.cr | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/controllers/events.cr b/src/controllers/events.cr index 20813487..3e04a2df 100644 --- a/src/controllers/events.cr +++ b/src/controllers/events.cr @@ -1073,7 +1073,8 @@ class Events < Application # defaults to the current users email cal_id = user.email unless cal_id - event = client.get_event(user.email, id: event_id, calendar_id: cal_id) + # use try here or we'll get a 500 if the event doesn't exist + event = client.try &.get_event(user.email, id: event_id, calendar_id: cal_id) raise Error::NotFound.new("failed to find event #{event_id} searching on #{cal_id} as #{user.email}") unless event # User details From f2d7b620516ae522b01f45f35aed8902f57d5fab Mon Sep 17 00:00:00 2001 From: Mia Bennett Date: Tue, 18 Jun 2024 15:03:11 +0930 Subject: [PATCH 2/4] fix(events): [PPT-1390] return 404 instead of 500 if the event can't be found upstream. --- src/controllers/events.cr | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/controllers/events.cr b/src/controllers/events.cr index 3e04a2df..dc918f08 100644 --- a/src/controllers/events.cr +++ b/src/controllers/events.cr @@ -1073,9 +1073,11 @@ class Events < Application # defaults to the current users email cal_id = user.email unless cal_id - # use try here or we'll get a 500 if the event doesn't exist - event = client.try &.get_event(user.email, id: event_id, calendar_id: cal_id) - raise Error::NotFound.new("failed to find event #{event_id} searching on #{cal_id} as #{user.email}") unless event + begin + event = client.get_event(user.email, id: event_id, calendar_id: cal_id) + rescue PlaceCalendar::Exception + raise Error::NotFound.new("failed to find event #{event_id} searching on #{cal_id} as #{user.email}") unless event + end # User details user_email = tenant.service_account.try(&.downcase) || user.email.downcase From 83aa71503f2da024b529b89d403f0477855496c8 Mon Sep 17 00:00:00 2001 From: Mia Bennett Date: Tue, 18 Jun 2024 15:04:40 +0930 Subject: [PATCH 3/4] fix(events): [PPT-1390] return 404 instead of 500 if the event can't be found upstream. --- src/controllers/events.cr | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/controllers/events.cr b/src/controllers/events.cr index dc918f08..2cec9dbb 100644 --- a/src/controllers/events.cr +++ b/src/controllers/events.cr @@ -1076,8 +1076,9 @@ class Events < Application begin event = client.get_event(user.email, id: event_id, calendar_id: cal_id) rescue PlaceCalendar::Exception - raise Error::NotFound.new("failed to find event #{event_id} searching on #{cal_id} as #{user.email}") unless event + event = nil end + raise Error::NotFound.new("failed to find event #{event_id} searching on #{cal_id} as #{user.email}") unless event # User details user_email = tenant.service_account.try(&.downcase) || user.email.downcase From d17f3dc4bb7d9e0f7433055d9106abfaba666788 Mon Sep 17 00:00:00 2001 From: Mia Bennett Date: Tue, 18 Jun 2024 15:34:03 +0930 Subject: [PATCH 4/4] refactor(events): [PPT-1390] improve debug logging --- src/controllers/events.cr | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/controllers/events.cr b/src/controllers/events.cr index 2cec9dbb..94934f5b 100644 --- a/src/controllers/events.cr +++ b/src/controllers/events.cr @@ -1075,7 +1075,8 @@ class Events < Application begin event = client.get_event(user.email, id: event_id, calendar_id: cal_id) - rescue PlaceCalendar::Exception + rescue ex : PlaceCalendar::Exception + Log.debug { "upstream failed to find event #{event_id}, status: #{ex.http_status}, body: #{ex.http_body}" } event = nil end raise Error::NotFound.new("failed to find event #{event_id} searching on #{cal_id} as #{user.email}") unless event