JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

RecordNotFound should receive associated resource class

Open
#747 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Type: Enhancement
Dominant language
Ruby
Stars
2.3k
Forks
546
PR merge metrics
No merged PRs in 30d

Description

The message from record not found only pass ID as attribute.
I think it would be better to pass the resource class as well so that we can have something like

 detail: I18n.translate('jsonapi-resources.exceptions.record_not_found.detail',
                                                   default: "The #{resource.name} identified by #{id} could not be found.", id: id, type: resource.class))]

Or maybe the associated activerecord class
This is the current implementation

 class RecordNotFound < Error
      attr_accessor :id
      def initialize(id)
        @id = id
      end

      def errors
        [JSONAPI::Error.new(code: JSONAPI::RECORD_NOT_FOUND,
                            status: :not_found,
                            title: I18n.translate('jsonapi-resources.exceptions.record_not_found.title',
                                                  default: 'Record not found'),
                            detail: I18n.translate('jsonapi-resources.exceptions.record_not_found.detail',
                                                   default: "The record identified by #{id} could not be found.", id: id))]
      end
    end

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the RecordNotFound class and its callers, focusing on the JSONAPI::Error detail translation and the record_not_found I18n key shown in the issue. Resolve whether the error should expose the JSON:API resource class or its associated ActiveRecord class, then verify that the resulting not-found message includes the intended resource context and ID.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
api, backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.