Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/linkup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
LinkupBudgetLimitExceededError,
LinkupFailedFetchError,
LinkupFetchResponseTooLargeError,
LinkupFetchTargetNotFoundError,
LinkupFetchTargetUnreachableError,
LinkupFetchUnsupportedContentTypeError,
LinkupFetchUrlIsFileError,
Expand Down Expand Up @@ -52,6 +53,7 @@
FetchImageExtraction = LinkupFetchImageExtraction
FetchResponse = LinkupFetchResponse
FetchResponseTooLargeError = LinkupFetchResponseTooLargeError
FetchTargetNotFoundError = LinkupFetchTargetNotFoundError
FetchTargetUnreachableError = LinkupFetchTargetUnreachableError
FetchUnsupportedContentTypeError = LinkupFetchUnsupportedContentTypeError
FetchTask = LinkupFetchTask
Expand Down Expand Up @@ -93,6 +95,7 @@
"FetchImageExtraction",
"FetchResponse",
"FetchResponseTooLargeError",
"FetchTargetNotFoundError",
"FetchTargetUnreachableError",
"FetchTask",
"FetchTaskInput",
Expand All @@ -109,6 +112,7 @@
"LinkupFetchImageExtraction",
"LinkupFetchResponse",
"LinkupFetchResponseTooLargeError",
"LinkupFetchTargetNotFoundError",
"LinkupFetchTargetUnreachableError",
"LinkupFetchTask",
"LinkupFetchTaskInput",
Expand Down
13 changes: 11 additions & 2 deletions src/linkup/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
LinkupBudgetLimitExceededError,
LinkupFailedFetchError,
LinkupFetchResponseTooLargeError,
LinkupFetchTargetNotFoundError,
LinkupFetchTargetUnreachableError,
LinkupFetchUnsupportedContentTypeError,
LinkupFetchUrlIsFileError,
Expand Down Expand Up @@ -1030,8 +1031,9 @@ def fetch(

Raises:
LinkupInvalidRequestError: If the provided URL is not valid.
LinkupFailedFetchError: If the provided URL is not found or can't be fetched.
LinkupFailedFetchError: If the provided URL can't be fetched.
LinkupFetchResponseTooLargeError: If the fetch response is too large.
LinkupFetchTargetNotFoundError: If the target URL is not found.
LinkupFetchTargetUnreachableError: If the target URL cannot be reached.
LinkupFetchUnsupportedContentTypeError: If the URL resolves to an unsupported content
type.
Expand Down Expand Up @@ -1090,8 +1092,9 @@ async def async_fetch(

Raises:
LinkupInvalidRequestError: If the provided URL is not valid.
LinkupFailedFetchError: If the provided URL is not found or can't be fetched.
LinkupFailedFetchError: If the provided URL can't be fetched.
LinkupFetchResponseTooLargeError: If the fetch response is too large.
LinkupFetchTargetNotFoundError: If the target URL is not found.
LinkupFetchTargetUnreachableError: If the target URL cannot be reached.
LinkupFetchUnsupportedContentTypeError: If the URL resolves to an unsupported content
type.
Expand Down Expand Up @@ -1338,6 +1341,12 @@ def _raise_linkup_error(self, response: httpx.Response) -> None:
"The provided URL's response is too large to be processed.\n"
f"Original error message: {error_msg}."
)
if code == "FETCH_TARGET_NOT_FOUND":
raise LinkupFetchTargetNotFoundError(
"The Linkup API returned a fetch target not found error (400). "
"The target URL was not found.\n"
f"Original error message: {error_msg}."
)
if code == "FETCH_TARGET_UNREACHABLE":
raise LinkupFetchTargetUnreachableError(
"The Linkup API returned a fetch target unreachable error (400). "
Expand Down
9 changes: 9 additions & 0 deletions src/linkup/_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ class LinkupFetchResponseTooLargeError(Exception):
pass


class LinkupFetchTargetNotFoundError(Exception):
"""Fetch target not found error.

Raised when the API reports that the target URL was not found.
"""

pass


class LinkupFetchTargetUnreachableError(Exception):
"""Fetch target unreachable error, raised when the Linkup API returns a 400 status code.

Expand Down
13 changes: 13 additions & 0 deletions tests/unit/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,19 @@ async def test_async_fetch(
""",
linkup.FetchResponseTooLargeError,
),
(
400,
b"""
{
"error": {
"code": "FETCH_TARGET_NOT_FOUND",
"message": "The target URL was not found",
"details": []
}
}
""",
linkup.FetchTargetNotFoundError,
),
(
400,
b"""
Expand Down
Loading