Skip to content

refactor make_response to be easier to follow#2256

Merged
davidism merged 1 commit intopallets:masterfrom
davidism:refactor-make_response
Apr 25, 2017
Merged

refactor make_response to be easier to follow#2256
davidism merged 1 commit intopallets:masterfrom
davidism:refactor-make_response

Conversation

@davidism
Copy link
Copy Markdown
Member

@davidism davidism commented Apr 25, 2017

  • be explicit about how tuples are unpacked
  • allow bytes for status value
  • allow Headers for headers value
  • use TypeError instead of ValueError
  • errors are more descriptive
  • document that view must not return None
  • update documentation about return values
  • test more response types
  • test error messages

closes #1676

TypeError is more correct by definition (wrong type to function), and I don't think anyone should be catching that error anyway (what would it mean to do that?), so I'm ok if this somehow breaks some code. This is also consistent with what force_type returns for bad input.

I had to get a bit creative with displaying the error from force_type while injecting a new descriptive message. It would be nice if we could just use raise new_error from original_error, but that's Python 3 only.

These error messages will hopefully help avoid a class of questions that are frequently asked on Stack Overflow. In particular, there was no error about incorrect types that made it to force_type, so users trying to return JSON with something like return True would get a mysterious "bool object is not callable" error.

Loading
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant