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

Api problem message as json #15

Open
weierophinney opened this issue Dec 31, 2019 · 4 comments
Open

Api problem message as json #15

weierophinney opened this issue Dec 31, 2019 · 4 comments

Comments

@weierophinney
Copy link
Contributor

When I make request on non existing resource page /users?page=1234567 I receive:

{
  "type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
  "title": "Conflict",
  "status": 409,
  "detail": "Invalid page provided"
}

As you see it a api problem. However in Content-Type you can find application/json instead of application/problem+json


Originally posted by @snapshotpl at zfcampus/zf-hal#121

@weierophinney
Copy link
Contributor Author

I can confirm this...


Originally posted by @Wilt at zfcampus/zf-hal#121 (comment)

@weierophinney
Copy link
Contributor Author

A pull request for this issue can be found here: zfcampus/zf-hal#127


Originally posted by @Wilt at zfcampus/zf-hal#121 (comment)

@weierophinney
Copy link
Contributor Author

Maybe good idea to add a test?


Originally posted by @Wilt at zfcampus/zf-hal#121 (comment)

@weierophinney
Copy link
Contributor Author

Another solution would be to include a

    /**
     * Does the payload represent a ApiProblem?
     *
     * @return bool
     */
    public function isApiProblem()
    {
        $payload = $this->getPayload();
        return ($payload instanceof ApiProblem);
    }

And use this method inside injectResponse method:

    if ($model instanceof HalJsonModel){
        if($model->isApiProblem){
            $contentType = 'application/problem+json'
        }elseif($model->isCollection() || $model->isEntity()){
            $contentType = 'application/hal+json';
        }
    }

Originally posted by @Wilt at zfcampus/zf-hal#121 (comment)

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

1 participant