jsonapi icon indicating copy to clipboard operation
jsonapi copied to clipboard

Support Unmarshaling of Errors

Open DQSevilla opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe. Currently our lib does not support Unmarshaling errors because it is not seen in requests to JSON:API servers, but it would be a nice-to-have feature for testing / consuming responses from JSON:API-servers.

Describe the solution you'd like Unmarshal works for jsonapi.Error

Describe alternatives you've considered N/A

Additional context There are other things that this lib does not Unmarshal, like links or relationship metas, that may be interesting to do as well

DQSevilla avatar May 15 '23 17:05 DQSevilla

This would be nice to have, as a workaround I am doing the following:

import (
  "encoding/json"
  "github.com/DataDog/jsonapi"
)

// ...

// https://github.com/DataDog/jsonapi/issues/36
type jsonAPIDocumentWithErrors struct {
	Errors []*jsonapi.Error `json:"errors"`
}

// ....

var errorDoc jsonAPIDocumentWithErrors
_ = json.Unmarshal(bytes, &errorDoc)

// check errorDoc.Errors

johnemau avatar Mar 26 '25 17:03 johnemau