Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to keep error title *and* detail in the error message? #368

Open
zackxu1 opened this issue Jul 1, 2020 · 3 comments
Open

How to keep error title *and* detail in the error message? #368

zackxu1 opened this issue Jul 1, 2020 · 3 comments

Comments

@zackxu1
Copy link

zackxu1 commented Jul 1, 2020

Hello.

Due to this line in the error_collector.rb, we're not able to retrieve the error detail if a request (for example save) fails.

Could this be fixed or is there an easy way to override this logic?

Thank you.

@zackxu1
Copy link
Author

zackxu1 commented Jul 1, 2020

I see that we have access to last_result_set.errors on the resource object, so we can access the error detail field, which the provided errors method has omitted. It would be nice to make this configurable and avoid custom code to access the detail field. Also, if we use last_result_set.errors directly in application code, is it guaranteed to work in the future? If there's a better solution, please provide details. Thank you

@senid231
Copy link
Member

senid231 commented Jul 8, 2020

currently you can monkey patch JsonApiClient::ErrorCollector::Error to make it work
but it will affect all resources

class JsonApiClient::ErrorCollector::Error
  def error_key
     super # you can override error key too
  end

  def error_msg
    title
  end

In future releases I think we can expose it to JsonApiClient::Resource

something like

class Person < JsonApiClient::Resource
  def generate_error(error_object)
    [error_key, error_msg]
  end
end

@samlachance
Copy link

I also ran into this issue and am getting by with the monkeypatch solution.

For reference, the api that I'm interacting with uses Graphiti: https://www.graphiti.dev/

For each validation error, the title is Validation Error and the actual message is contained in the detail key.

While they may not be following the json api spec correctly, your proposed future release change would be appreciated to handle cases like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants