Skip to content

Commit 3a07db6

Browse files
committed
Merge pull request #601 from paysavvy/fix/exception_in_rescue
Check method defined in rescue block, add fallback
2 parents 81f980f + bc76809 commit 3a07db6

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

lib/jsonapi/active_record_operations_processor.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,18 @@ def rollback
1818
# Catch errors that should be handled before JSONAPI::Exceptions::Error
1919
# and other unprocessed exceptions
2020
def process_operation(operation)
21-
with_default_handling do
21+
with_default_handling do
2222
begin
2323
operation.apply
2424
rescue ActiveRecord::DeleteRestrictionError => e
2525
record_locked_error = JSONAPI::Exceptions::RecordLocked.new(e.message)
2626
return JSONAPI::ErrorsOperationResult.new(record_locked_error.errors[0].code, record_locked_error.errors)
2727

2828
rescue ActiveRecord::RecordNotFound
29-
record_not_found = JSONAPI::Exceptions::RecordNotFound.new(operation.associated_key)
29+
key = operation.respond_to?(:associated_key) ? operation.associated_key : :unavailable
30+
record_not_found = JSONAPI::Exceptions::RecordNotFound.new(key)
3031
return JSONAPI::ErrorsOperationResult.new(record_not_found.errors[0].code, record_not_found.errors)
3132
end
32-
end
33+
end
3334
end
3435
end

0 commit comments

Comments
 (0)