| 2081 | |
| 2082 | @classmethod |
| 2083 | def build_exception(cls, |
| 2084 | base_exc, # type: pycbc_exception |
| 2085 | mapping=None, # type: Dict[str, CouchbaseException] |
| 2086 | ) -> CouchbaseException: |
| 2087 | exc_class = None |
| 2088 | err_ctx = None |
| 2089 | ctx = base_exc.error_context() |
| 2090 | if ctx is None: |
| 2091 | exc_class = PYCBC_ERROR_MAP.get(base_exc.err(), CouchbaseException) |
| 2092 | err_info = base_exc.error_info() |
| 2093 | else: |
| 2094 | err_ctx = ErrorContext.from_dict(**ctx) |
| 2095 | err_info = base_exc.error_info() |
| 2096 | |
| 2097 | if isinstance(err_ctx, HTTPErrorContext): |
| 2098 | exc_class = ErrorMapper._parse_http_context(err_ctx, mapping, err_info=err_info) |
| 2099 | |
| 2100 | if isinstance(err_ctx, KeyValueErrorContext): |
| 2101 | if mapping is None: |
| 2102 | mapping = KV_ERROR_CONTEXT_MAPPING |
| 2103 | exc_class = ErrorMapper._parse_kv_context(err_ctx, mapping) |
| 2104 | |
| 2105 | if isinstance(err_ctx, QueryErrorContext): |
| 2106 | if mapping is None: |
| 2107 | mapping = QUERY_ERROR_MAPPING |
| 2108 | exc_class = ErrorMapper._parse_http_context(err_ctx, mapping) |
| 2109 | |
| 2110 | if exc_class is None: |
| 2111 | exc_class = PYCBC_ERROR_MAP.get(base_exc.err(), CouchbaseException) |
| 2112 | |
| 2113 | exc = exc_class(base=base_exc, exc_info=err_info, context=err_ctx) |
| 2114 | return exc |