Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Api problem message as json #121

Open
snapshotpl opened this issue Sep 22, 2015 · 5 comments
Open

Api problem message as json #121

snapshotpl opened this issue Sep 22, 2015 · 5 comments

Comments

@snapshotpl
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

@Wilt
Copy link
Contributor

Wilt commented Oct 16, 2015

I can confirm this...

@Wilt
Copy link
Contributor

Wilt commented Oct 16, 2015

A pull request for this issue can be found here: #127

@Wilt
Copy link
Contributor

Wilt commented Oct 16, 2015

Maybe good idea to add a test?

@Wilt
Copy link
Contributor

Wilt commented Oct 16, 2015

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';
        }
    }

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas-api-tools/api-tools-hal; a new issue has been opened at laminas-api-tools/api-tools-hal#15.

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

No branches or pull requests

3 participants