-
Notifications
You must be signed in to change notification settings - Fork 631
[CO-417] Add more friendly 415 Unsupported Media Type error #3727
Conversation
35fee0c
to
0dddf95
Compare
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late review!
, "diagnostic" .= diagnostic | ||
, "message" .= msg | ||
] | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's have it as a middleware instead, don't you think? And, let's re-use code actually serializing jsend errors toJSON
unsupportedMimeTypeMiddleware :: Middleware
unsupportedMimeTypeMiddleware = ifResponse ((== status415) . responseStatus) $ responseBuilder status415
[ ("Content-Type", "application/json") ]
(fromByteString . toStrict . encode UnsupportedMimeTypeError
Something along those lines, with UnsupportedMimeTypeError
defined somewhere as a plain type, like other errors, not forgetting the example documentation in Swagger.hs ❤️
da86a5a
to
2d86d1c
Compare
Made changes as requested:
Now it outputs:
Code rebased, and squashed |
Both AppVeyor failures are due to timeouts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A minor comment, but looks good now 👍
| otherwise = r | ||
|
||
unsupportedMimeTypeMiddleware :: Middleware | ||
unsupportedMimeTypeMiddleware = modifyResponse responseModifier |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since responseModifier
is solely related to the above function, it would make sense to have it under a where
clause. It doesn't make sense to use responseModifier
as it is in any other context 👍
May you add an entry in the CHANGELOG, explaining that we now have more developer-friendly errors for wrong content-type ? Incidentally, that is a breaking change 🙃 ... |
|
||
instance Buildable UnsupportedMimeTypeError where | ||
build _ = | ||
bprint "The API expects the Content-Type's main MIME-type to be 'application/json'" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should display what get passed as Text
to the UnsupportedMimeTypePresent
constructor ? Don't you think?
golden_UnsupportedMimeTypeError_UnsupportedMimeTypePresent = | ||
goldenTestJSON | ||
(UnsupportedMimeTypePresent "test") | ||
"test/golden/UnsupportedMimeTypeError_UnsupportedMimeTypePresent" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
2d86d1c
to
f71f0b4
Compare
[CO-417] stack2nix patch [CO-417] Introducing UnsupportedMimeTypeError and delegating code to middleware [CO-417] Small improvements and CHANGELOG entry
Changes:
Commits squashed, was up to date against develop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Description
Implement more friendly 415 Unsupported Media Type error.
BEFORE
AFTER
Linked issue
https://iohk.myjetbrains.com/youtrack/issue/CO-417
Type of change
Developer checklist
Testing checklist
QA Steps
Screenshots (if available)