From 3e18e05330ac8c1101845db650d7cd62b0fa8260 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 27 Oct 2022 14:30:52 +0200 Subject: [PATCH] Fix uncaught error when invalid date is supplied to API (#19480) Fix #19213 --- app/controllers/api/base_controller.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/controllers/api/base_controller.rb b/app/controllers/api/base_controller.rb index 7ce6599c52..c46fde65b2 100644 --- a/app/controllers/api/base_controller.rb +++ b/app/controllers/api/base_controller.rb @@ -24,6 +24,10 @@ class Api::BaseController < ApplicationController render json: { error: 'Duplicate record' }, status: 422 end + rescue_from Date::Error do + render json: { error: 'Invalid date supplied' }, status: 422 + end + rescue_from ActiveRecord::RecordNotFound do render json: { error: 'Record not found' }, status: 404 end