@@ -94,9 +94,9 @@ def search(
94
94
)
95
95
96
96
response : httpx .Response = self ._request (
97
- method = "GET " ,
97
+ method = "POST " ,
98
98
url = "/search" ,
99
- params = params ,
99
+ data = params ,
100
100
timeout = None ,
101
101
)
102
102
if response .status_code != 200 :
@@ -207,39 +207,60 @@ async def _async_request(
207
207
)
208
208
209
209
def _raise_linkup_error (self , response : httpx .Response ) -> None :
210
- message : Any = response .json ().get ("message" , "No message provided" )
211
- message = ", " .join (message ) if isinstance (message , list ) else str (message )
212
-
213
- if response .status_code == 400 :
214
- if message == "The query did not yield any result" :
215
- raise LinkupNoResultError (
216
- "The Linkup API returned a no result error (400). Try rephrasing you query.\n "
217
- f"Original error message: { message } ."
210
+ error_data = response .json ()
211
+
212
+ if "error" in error_data :
213
+ error = error_data ["error" ]
214
+ code = error .get ("code" , "" )
215
+ message = error .get ("message" , "" )
216
+ details = error .get ("details" , [])
217
+
218
+ error_msg = f"{ message } "
219
+ if details and isinstance (details , list ):
220
+ for detail in details :
221
+ if isinstance (detail , dict ):
222
+ field = detail .get ("field" , "" )
223
+ field_message = detail .get ("message" , "" )
224
+ error_msg += f" { field } : { field_message } "
225
+
226
+ if response .status_code == 400 :
227
+ if code == "SEARCH_QUERY_NO_RESULT" :
228
+ raise LinkupNoResultError (
229
+ "The Linkup API returned a no result error (400). "
230
+ "Try rephrasing you query.\n "
231
+ f"Original error message: { error_msg } ."
232
+ )
233
+ else :
234
+ raise LinkupInvalidRequestError (
235
+ "The Linkup API returned an invalid request error (400). Make sure the "
236
+ "parameters you used are valid (correct values, types, mandatory "
237
+ "parameters, etc.) and you are using the latest version of the Python "
238
+ "SDK.\n "
239
+ f"Original error message: { error_msg } ."
240
+ )
241
+ elif response .status_code == 401 :
242
+ raise LinkupAuthenticationError (
243
+ "The Linkup API returned an authentication error (401). Make sure your API "
244
+ "key is valid.\n "
245
+ f"Original error message: { error_msg } ."
246
+ )
247
+ elif response .status_code == 403 :
248
+ raise LinkupAuthenticationError (
249
+ "The Linkup API returned an authorization error (403). Make sure your API "
250
+ "key is valid.\n "
251
+ f"Original error message: { error_msg } ."
252
+ )
253
+ elif response .status_code == 429 :
254
+ raise LinkupInsufficientCreditError (
255
+ "The Linkup API returned an insufficient credit error (429). Make sure "
256
+ "you haven't exhausted your credits.\n "
257
+ f"Original error message: { error_msg } ."
218
258
)
219
259
else :
220
- raise LinkupInvalidRequestError (
221
- "The Linkup API returned an invalid request error (400). Make sure the "
222
- "parameters you used are valid (correct values, types, mandatory parameters, "
223
- "etc.) and you are using the latest version of the Python SDK.\n "
224
- f"Original error message: { message } ."
260
+ raise LinkupUnknownError (
261
+ f"The Linkup API returned an unknown error ({ response .status_code } ).\n "
262
+ f"Original error message: ({ error_msg } )."
225
263
)
226
- elif response .status_code == 403 :
227
- raise LinkupAuthenticationError (
228
- "The Linkup API returned an authentication error (403). Make sure your API "
229
- "key is valid.\n "
230
- f"Original error message: { message } ."
231
- )
232
- elif response .status_code == 429 :
233
- raise LinkupInsufficientCreditError (
234
- "The Linkup API returned an insufficient credit error (429). Make sure "
235
- "you haven't exhausted your credits.\n "
236
- f"Original error message: { message } ."
237
- )
238
- else :
239
- raise LinkupUnknownError (
240
- f"The Linkup API returned an unknown error ({ response .status_code } ).\n "
241
- f"Original error message: ({ message } )."
242
- )
243
264
244
265
def _get_search_params (
245
266
self ,
0 commit comments