Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Should we throw in our formatters if the list of SupportedMediaTypes is empty? #4050

Closed
javiercn opened this issue Feb 5, 2016 · 3 comments
Assignees
Milestone

Comments

@javiercn
Copy link
Member

javiercn commented Feb 5, 2016

In our input and output formatters we have a few pieces of code like

SupportedMediaTypes.Count > 0 ? SupportedMediaTypes : null.
if(SupportedMediaTypes.Count > 0)...

Having no media types in the list after the formatter has been configured during startup is most likely a configuration error. This can happen in two scenarios:

  • A user is configuring an existing formatter and somehow clears the supported media types list and forgets to add at least a media type.
  • A user is implementing it's own formatter by extending one of our base classes and forgets do add media types to the list of supported media types inside the constructor or during the initialization of their app.

Should we just do this check in the places where we use it and throw an exception in that situation? The benefit is that the user gets an early error instead of a behavior that depends on the configuration of other pieces of the system. (Maybe the next formatter writes/reads the request/response) or we return something else like 406 or 415.

It also simplifies our implementations as we don't need to be checking if there is one element in the list of supported media types through the code

@Eilon Eilon added this to the 1.0.0-rc2 milestone Feb 5, 2016
@Eilon
Copy link
Member

Eilon commented Feb 5, 2016

Discussed with @javiercn in person and this seems alright to me, but please discuss with @rynowak before starting.

@rynowak
Copy link
Member

rynowak commented Feb 5, 2016

I'm a little concerned about the case where someone uses the base class, but overrides CanWrite to do custom logic that doesn't rely on SupportedMediaTypes. As long as we do this in our CanWrite implementation there's no regression for this case.

javiercn added a commit that referenced this issue Feb 6, 2016
…tentTypes when the list of media types is empty
javiercn added a commit that referenced this issue Feb 6, 2016
…tentTypes when the list of media types is empty
javiercn added a commit that referenced this issue Feb 16, 2016
…tentTypes when the list of media types is empty
@Eilon
Copy link
Member

Eilon commented Feb 17, 2016

Done?

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

No branches or pull requests

3 participants