Function: createApiError()
@kortexya/reasoninglayer / createApiError
Function: createApiError()
Section titled “Function: createApiError()”createApiError(
status,body,headers):ApiError
Defined in: src/errors.ts:998
Factory function that creates the appropriate ApiError subclass for a given HTTP status.
Parameters
Section titled “Parameters”status
Section titled “status”number
HTTP status code.
unknown
Parsed response body.
headers
Section titled “headers”Headers
Response headers.
Returns
Section titled “Returns”The appropriate error subclass instance.
Remarks
Section titled “Remarks”Status code mapping:
- 400 → BadRequestError
- 404 → NotFoundError
- 409 → DerivedFactWriteError for
code: "write_targets_derived_fact", RuleTermWriteError forcode: "write_targets_rule", else ConstraintViolationError (reads the flatterm_id,featureandconstraintof the engine’sConstraintViolationResponse) - 412 → PreconditionFailedError (reads the current
ETagheader) - 428 → PreconditionRequiredError
- 422 → BulkRefusedError when the body names refused rows, NamedConstraintViolationError when it names the refusing constraint, else ApiError
- 429 → RateLimitError (parses rate limit headers)
- 503 → ServiceUnavailableError (a subclass of InternalServerError)
- 504 with
error_type: "timeout"→ DeadlineExceededError - other 500+ → InternalServerError
- Other 4xx → ApiError
The message is the body’s message string whenever there is one, whether
or not the body also carries an error field: the OSFQL, SPARQL and
property-graph error bodies carry error_type + message and no error.
errorCode is the body’s error string, when present.
Exported from the package root so that a caller can type a failure the SDK
did not throw itself, such as the error event of
conversation.sendMessageStream.
Example
Section titled “Example”const error = createApiError(503, { error: 'llm unavailable', message: 'llm unavailable' }, new Headers());error instanceof ServiceUnavailableError; // true