diff --git a/lib/api/v3/render/render_api.rb b/lib/api/v3/render/render_api.rb index 80c40e0132..a480d46137 100644 --- a/lib/api/v3/render/render_api.rb +++ b/lib/api/v3/render/render_api.rb @@ -42,17 +42,21 @@ module API end def context_object + begin + try_context_object + rescue ::ActiveRecord::RecordNotFound + fail API::Errors::InvalidRenderContext.new('Context does not exist!') + end + end + + def try_context_object if params[:context] - context_object = nil context = parse_context case context[:ns] when 'work_packages' - context_object = WorkPackage.visible(current_user).find_by_id(context[:id]) - end - - unless context_object - fail API::Errors::InvalidRenderContext.new('Context does not exist!') + WorkPackage.visible(current_user).find(context[:id]) + else end end end