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

Handle non-JSON 500 errors #359

Merged
merged 1 commit into from
Jan 26, 2021
Merged

Conversation

agrobbin
Copy link
Contributor

Closes #358.

Consider this WebMock'd request, which is based on a real-world scenario we ran into when the Slack API was down:

WebMock.stub_request(:post, 'https://slack.com/api/chat.postMessage').
  to_return(
    status: 500,
    body: <<~HTML
      <!DOCTYPE html>
      <html lang="en">
        <head>
          <meta charset="utf-8">
          <title>Server Error | Slack</title>
          <meta name="author" content="Slack">
        </head>
        <body></body>
      </html>
    HTML
  )

Before v0.16 (and #350), this raised a Faraday::ParsingError exception, and after those changes, it raises a Slack::Web::Api::Errors::ParsingError exception.

Looking further at the tests in #350, it appears while there is a test for status: 500, body: '{}', and there is a test for status: 200, body: '<html></html>, there is no test for the combination of the 2.

This adds that test, and makes it pass!

CHANGELOG.md Outdated Show resolved Hide resolved
@agrobbin agrobbin changed the title Refactor server error handling to account for non-JSON 500 errors Handle non-JSON 500 errors Jan 26, 2021
@agrobbin
Copy link
Contributor Author

@dblock just updated the CHANGELOG, commit message, and PR title here!

@agrobbin agrobbin requested a review from dblock January 26, 2021 13:13
@dblock dblock merged commit cddc898 into slack-ruby:master Jan 26, 2021
@dblock
Copy link
Collaborator

dblock commented Jan 26, 2021

Merged, thank you for fixing this the "right way" by moving middleware around, too.

@agrobbin
Copy link
Contributor Author

@dblock my pleasure, and thanks for the quick review + merge! Looking forward to this getting released.

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.

500 errors raise a ParsingError rather than an UnavailableError
2 participants