Skip to content
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

Fix to see content-type of error response #9

Merged
merged 4 commits into from
Nov 13, 2019

Conversation

makinoshi
Copy link
Member

@makinoshi makinoshi commented Nov 12, 2019

The kintone API sometimes returns HTML response, for example basic authentication fails.

So this PR changes error handing to see Content-Type and parse body only when it is application/json.

This PR makes kintone-clj return following response when basic authentication fails.

#kintone.types.KintoneResponse{:res nil,
                               :err {:status 401,
                                     :status-text "401",
                                     :response "<!DOCTYPE html>\r
                                                <html>\r
                                                <head>\r
                                                <meta charset=\"utf-8\">\r
                                                <title>Unauthorized</title>\r
                                                <meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\r
                                                <link rel=\"stylesheet\" href=\"/forest_error/css/style.css\">\r
                                                </head>\r
                                                \r
                                                <body>\r
                                                <div class=\"pagewrap\">\r
                                                  <div class=\"column\"> <img src=\"/forest_error/image/cloud.png\" width=\"178\" height=\"107\" alt=\"\">\r
                                                    <h2>アクセスするには認証が必要です。</h2>\r
                                                    <p>Code: 401 Unauthorized</p>\r
                                                  </div>\r
                                                </div>\r
                                                <div class=\"footer\">\r
                                                  <p>Copyright(C) Cybozu</p>\r
                                                </div>\r
                                                </body>\r
                                                </html>\r
                                                "}}

Copy link
Member

@liquidz liquidz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@makinoshi format-err looks good to me 👍
Please add tests to check whether response body is parsed as JSON or not by Content-Type header.

Copy link
Member

@liquidz liquidz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@makinoshi Thanks! LGTM

@makinoshi makinoshi merged commit 0e46ac9 into master Nov 13, 2019
@makinoshi makinoshi deleted the fix/kintone-api-returns-html-when-401-occurs branch November 13, 2019 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants