From 6d7daf6154b1edbfe9a0c0b297baab8cd45658f3 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Fri, 6 Dec 2019 22:40:06 +0100 Subject: [PATCH] Fix generic HTTP 500 error on duplicate records (#12563) Fix #12551 Fix #12547 --- 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 33df75b37..144fdd6ac 100644 --- a/app/controllers/api/base_controller.rb +++ b/app/controllers/api/base_controller.rb @@ -20,6 +20,10 @@ class Api::BaseController < ApplicationController render json: { error: e.to_s }, status: 422 end + rescue_from ActiveRecord::RecordNotUnique do + render json: { error: 'Duplicate record' }, status: 422 + end + rescue_from ActiveRecord::RecordNotFound do render json: { error: 'Record not found' }, status: 404 end