json-api-php icon indicating copy to clipboard operation
json-api-php copied to clipboard

data and errors MUST NOT coexist

Open langeuh opened this issue 7 years ago • 0 comments

The members data and errors MUST NOT coexist in the same document. see http://jsonapi.org/format/#document-top-level

I quickly solved it this way as any exception gets turned in to an error in my code

I extended Tobscure\JsonApi\Document and overwrote the toArray() function

public function toArray()
{
    // The members data and errors MUST NOT coexist in the same document.
    if (!empty($this->errors)) {
        $this->data = null;
        $this->links = null;
    }

    return parent::toArray();
}

Ideally this gets combined with #130

langeuh avatar Mar 07 '18 15:03 langeuh