def handle_4xx_errors()

in ees_microsoft_teams/microsoft_teams_requests.py [0:0]


    def handle_4xx_errors(self, response, object_type, request_url):
        """Returns the response when 4xx error occurs
        :param response: Response from Microsoft Graph API request
        :param object_type: The type of the object to get. The allowed values are teams, channels, channel_chat,
            channel_docs, calendar, user_chats, permissions and deletion
        :param request_url: Request URL for logging the message
        """
        response_data = self.parse_response_object(response)
        # Error 403 occurs when the current user is trying fetch the Teams and it's object which was
        # created by other user
        if response.status_code == 403 or (
            response.status_code == 404
            and response_data.get("error", {}).get("code") == "NotFound"
        ):
            if object_type not in [
                constant.CHANNELS,
                constant.ATTACHMENTS,
                constant.ROOT,
            ]:
                return {"value": []}

            new_response = Response()
            new_response._content = b'{"value": []}'
            new_response.status_code = 200
            return self.parse_response_object(new_response)
        elif not (object_type == "deletion" and response.status_code == 404):
            self.logger.error(
                f"Error: {response.reason}. Error while fetching {object_type} from Microsoft Teams, "
                f"url: {request_url}."
            )

        return response