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

add more response validation #16

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions tap_slack/client.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""REST client handling, including SlackStream base class."""

import time
from typing import Any, Dict, Text, Optional, List
from typing import Any, Dict, List, Optional, Text

from singer_sdk.streams import RESTStream
import requests
from singer_sdk.authenticators import BearerTokenAuthenticator
from singer_sdk.exceptions import FatalAPIError
from singer_sdk.streams import RESTStream


class SlackStream(RESTStream):
Expand Down Expand Up @@ -53,3 +55,15 @@ def get_next_page_token(self, response, previous_token):
if self.max_requests_per_minute:
time.sleep(60.0 / self.max_requests_per_minute)
return token

def validate_response(self, response: requests.Response) -> None:
super().validate_response(response)
resp_data = response.json()
body_status = resp_data.get("ok")
if not body_status:
msg = (
f" {response.status_code} Client Error: "
f" {response.reason} for path: {self.path}"
f" Status {body_status}: {resp_data}"
)
raise FatalAPIError(msg)