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

Parsing JSON Errors object #196

Closed
tjjjwxzq opened this issue Jul 5, 2016 · 1 comment
Closed

Parsing JSON Errors object #196

tjjjwxzq opened this issue Jul 5, 2016 · 1 comment

Comments

@tjjjwxzq
Copy link

tjjjwxzq commented Jul 5, 2016

The spec allows an error object to contain fields such as title, detail etc. However it only seems that the title field in added in and the rest ignored. Can the save method be modified to add in all the other fields as well? ( especially since the json_api adapter for ActiveModel::Serializers serializes errors with a source and detail field instead of a title field )

  def save
    return false unless valid?

    self.last_result_set =
      if persisted?
        self.class.requestor.update(self)
      else
        self.class.requestor.create(self)
      end

    if last_result_set.has_errors?
      last_result_set.errors.each do |error|
        if error.source_parameter
          errors.add(error.source_parameter, error.detail) if error.detail
          errors.add(error.source_parameter, error.title) if error.title
          #... check for other fields specified in the spec    
        else
          errors.add(:base, error.detail)
        end
      end
      false
    else
      errors.clear if errors
      mark_as_persisted!
      if updated = last_result_set.first
        self.attributes = updated.attributes
        relationships.attributes = updated.relationships.attributes
        clear_changes_information
      end
      true
    end
  end
@natemacinnes
Copy link
Contributor

@chingor13 can this please be adopted.

chingor13 added a commit that referenced this issue Sep 13, 2016
Allow use of `detail` next to `title` attribute on error parsing. Issue #196
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

2 participants