Skip to content

Exceptions

All exceptions inherit from UnihraError.

python
from unihra.exceptions import (
    UnihraError,
    UnihraConnectionError,
    UnihraValidationError,
    UnihraDependencyError,
    UnihraStorageError,
    UnihraApiError,
    InsufficientCreditsError,
    ParserError,
    AnalysisServiceError,
    CriticalOwnPageError,
    ReportGenerationError,
    TripletAnalysisError,
)

Hierarchy

UnihraError
├── UnihraConnectionError     # Network / timeout failures
├── UnihraValidationError     # Bad input (empty competitors, etc.)
├── UnihraDependencyError     # Missing optional package (pandas, openpyxl)
├── UnihraStorageError        # Failed to write files in analyze_and_save()
└── UnihraApiError            # API returned an error response
    ├── InsufficientCreditsError # HTTP 402 — balance below the task cost
    ├── ParserError           # code 1001 — a requested page was not included
    ├── AnalysisServiceError  # code 1002 — internal analysis failure
    ├── CriticalOwnPageError  # code 1003 — your own page is unreachable
    ├── ReportGenerationError # code 1004 — failed to generate the report
    └── TripletAnalysisError  # code 1005 — Knowledge Graph extraction failed

Usage

python
from unihra import UnihraClient, UnihraError
from unihra.exceptions import CriticalOwnPageError, InsufficientCreditsError, ParserError

client = UnihraClient(api_key="YOUR_KEY")

try:
    result = client.analyze(
        own_page="https://example.com",
        competitors=["https://comp.com"],
    )
except InsufficientCreditsError:
    print("Not enough credits. Check client.get_limits() and top up your balance.")
except CriticalOwnPageError:
    print("Your page is unreachable. Check the URL and try again.")
except ParserError as e:
    print(f"A requested competitor page was not included: {e}")
except UnihraError as e:
    print(f"API error: {e}")

UnihraApiError Attributes

python
try:
    result = client.analyze(...)
except UnihraApiError as e:
    print(e.code)     # int, e.g. 1001
    print(e.message)  # str, human-readable
    print(e.raw)      # dict, full API error payload

Error Code Reference

CodeExceptionCause
402InsufficientCreditsErrorAccount balance is below the task cost (1 credit standard, 5 with triplets)
1001ParserErrorA requested page was not included in the analysis
1002AnalysisServiceErrorInternal analysis service failure
1003CriticalOwnPageErrorYour own page returned an error or is unreachable
1004ReportGenerationErrorFailed to compile the final report
1005TripletAnalysisErrorKnowledge Graph extraction failed
9999UnihraApiErrorUnknown error