Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

IRI Converter Exception Messages #2172

Closed
ragboyjr opened this issue Aug 22, 2018 · 6 comments
Closed

IRI Converter Exception Messages #2172

ragboyjr opened this issue Aug 22, 2018 · 6 comments

Comments

@ragboyjr
Copy link
Contributor

The default IRI Converter uses the symfony router to handle the generation of the IRI values per entity. If there are any issues with IRI generation or lookup by IRI, the exceptions that get thrown are hard to understand/misleading because the errors will be associated with Routing and not with denormalizing an entity or fetching an entity by an IRI.

Here are a few examples of some scenarios that generate errors with the IRI Converter and have confusing error messages:

  1. No item route associated with the type "%s"
  2. No collection route associated with type "%s"
  3. No route matches "%s".

You can get errors 1 and 2 if API Platform tries to serialize an entity that does not have a GET item/collection operation defined which is common when working with DTO's. See this Stackoverflow Post

Error 3 can show up if you pass in malformed IRI value for a relationship entity.

POST books
{
    "title": "Some Value"
    "author": "badvalue" // should be an iri formatted like /authors/1
}

I think a possible solution for friendlier error messages would be to catch exceptions thrown in the in the normalizers and give error messages that are closer to the actual problem.

@teohhanhui
Copy link
Contributor

teohhanhui commented Aug 27, 2018

  1. No item route associated with the type "%s"
  2. No collection route associated with type "%s"

You can get errors 1 and 2 if API Platform tries to serialize an entity that does not have a GET item/collection operation defined which is common when working with DTO's.

Actually the exception messages here sound exactly correct to me.

@teohhanhui
Copy link
Contributor

But I think no. 3 should be fixed 😄

@teohhanhui
Copy link
Contributor

teohhanhui commented Aug 27, 2018

The problem mentioned in the SO question really is more complicated. I still believe we need to have better support for DTOs / resource representation classes by having a 2-pass process: #2053

@ragboyjr
Copy link
Contributor Author

@teohhanhui I think the issue I personally had with errors 1 and 2, is that the error made no sense in the context of what was going on.

I had no idea why a route was even trying to be generated for my Model. It wasn't till i learned that API platform uses the symfony router to generate the IRI, did the error kind of make sense. I think if the error included a clause like No item route associated with type "%s" when generating the IRI during serialization, that would be a bit clearer IMHO.

@teohhanhui
Copy link
Contributor

Sure, I guess we could catch the exception and wrap it. :)

@soyuka
Copy link
Member

soyuka commented Sep 6, 2018

Hi, my solution to avoid declaring a get item operation when I don't want any is to decorate the IriConverter and add an attribute to my resource: https://gist.github.com/soyuka/a7a58732792872f000a09f79741042a4

/edit: whooops wrong issue leaving the comment anyway just in case.

@soyuka soyuka removed the question label Nov 6, 2022
@api-platform api-platform locked and limited conversation to collaborators Nov 6, 2022
@soyuka soyuka converted this issue into discussion #5131 Nov 6, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

3 participants