1# Copyright 2017, Google LLC All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15from __future__ import absolute_import
16
17from enum import Enum
18from google.api_core.exceptions import GoogleAPICallError
19from typing import Optional
20
21
22class AcknowledgeStatus(Enum):
23 SUCCESS = 1
24 PERMISSION_DENIED = 2
25 FAILED_PRECONDITION = 3
26 INVALID_ACK_ID = 4
27 OTHER = 5
28
29
30class AcknowledgeError(GoogleAPICallError):
31 """Error during ack/modack/nack operation on exactly-once-enabled subscription."""
32
33 def __init__(self, error_code: AcknowledgeStatus, info: Optional[str]):
34 self.error_code = error_code
35 self.info = info
36 message = None
37 if info:
38 message = str(self.error_code) + " : " + str(self.info)
39 else:
40 message = str(self.error_code)
41 super(AcknowledgeError, self).__init__(message)
42
43
44__all__ = ("AcknowledgeError",)