|
15 | 15 | )
|
16 | 16 | from .person import Person
|
17 | 17 |
|
18 |
| -NOT_FOUND_ERROR_RESPONSE = 'No se han encontrado coincidencias' |
19 |
| -INVALID_TOKEN_ERROR_RESPONSE = ( |
20 |
| - 'El token proporcionado para realizar esta acción es inválido' |
21 |
| -) |
22 |
| -INVALID_PLAN_ERROR_RESPONSE = ( |
23 |
| - 'Tu plan de consultas ha expirado, ' |
24 |
| - 'por favor actualiza tu plan para continuar usando la API' |
25 |
| -) |
26 |
| - |
27 | 18 |
|
28 | 19 | @dataclass
|
29 | 20 | class Client:
|
@@ -145,24 +136,34 @@ async def search(
|
145 | 136 | 'GET', search_url, params=params, headers=headers
|
146 | 137 | )
|
147 | 138 | except httpx.HTTPStatusError as exc:
|
148 |
| - if exc.response.status_code == 401: |
149 |
| - self._invalidate_auth_token() |
150 |
| - raise InvalidTokenError(exc.response) |
151 |
| - if exc.response.status_code == 403: |
152 |
| - raise InsufficientBalanceError(exc.response) |
153 |
| - raise QuienEsQuienError(exc.response) from exc |
| 139 | + match exc.response.status_code: |
| 140 | + case 401: |
| 141 | + self._invalidate_auth_token() |
| 142 | + raise InvalidTokenError(exc.response) |
| 143 | + case 403: |
| 144 | + raise InsufficientBalanceError(exc.response) |
| 145 | + case _: |
| 146 | + raise QuienEsQuienError(exc.response) from exc |
154 | 147 |
|
155 | 148 | response_data = response.json()
|
156 | 149 | if not response_data.get('success', False):
|
157 | 150 | status = response_data.get('status', '')
|
158 |
| - if status == NOT_FOUND_ERROR_RESPONSE: |
159 |
| - raise PersonNotFoundError(response) |
160 |
| - if status == INVALID_TOKEN_ERROR_RESPONSE: |
161 |
| - self._invalidate_auth_token() |
162 |
| - raise InvalidTokenError(response) |
163 |
| - if status == INVALID_PLAN_ERROR_RESPONSE: |
164 |
| - raise InvalidPlanError(response) |
165 |
| - raise QuienEsQuienError(response) |
| 151 | + match status: |
| 152 | + case 'No se han encontrado coincidencias': |
| 153 | + raise PersonNotFoundError(response) |
| 154 | + case ( |
| 155 | + 'El token proporcionado para realizar esta acción ' |
| 156 | + 'es inválido' |
| 157 | + ): |
| 158 | + self._invalidate_auth_token() |
| 159 | + raise InvalidTokenError(response) |
| 160 | + case ( |
| 161 | + 'Tu plan de consultas ha expirado, por favor ' |
| 162 | + 'actualiza tu plan para continuar usando la API' |
| 163 | + ): |
| 164 | + raise InvalidPlanError(response) |
| 165 | + case _: |
| 166 | + raise QuienEsQuienError(response) |
166 | 167 |
|
167 | 168 | matched_persons = [
|
168 | 169 | Person(**person_data)
|
|
0 commit comments