Pular para o conteúdo principal

externalStarlightError

This error is thrown every time a problem occurs when requesting something from Starlight’s APIs. When it does, you can inspect the attached response to verify what kind of problem happened and handle it accordingly.

Hierarchy

  • Error
    • StarlightError

Index

Constructors

externalconstructor

  • new StarlightError(message: string, response: Response): StarlightError
  • Parameters

    • externalmessage: string
    • externalresponse: Response

    Returns StarlightError

Properties

externalmessage

message: string

externalname

name: string

externalresponse

response: Response

The response provided by the fetch method when the error occurred.

@example

Using the response property to handle 404 errors.

import Starlight, { StarlightError } from '@starlightcms/js-sdk'

// Returns either an Entry, null on 404 errors, or false in all other cases
const requestEntry = async (slug) => {
try {
const response = await Starlight.posts.entries.get(slug)

return response.data
} catch (error) {
if (error instanceof StarlightError && error.response.status === 404) {
// Return null to indicate a 404 error
return null
}

// Return false in all other error scenarios
return false
}
}
@see

externaloptionalstack

stack?: string

staticexternaloptionalprepareStackTrace

prepareStackTrace?: (err: Error, stackTraces: CallSite[]) => any

Type declaration

staticexternalstackTraceLimit

stackTraceLimit: number

Methods

staticexternalcaptureStackTrace

  • captureStackTrace(targetObject: object, constructorOpt?: Function): void
  • Create .stack property on a target object


    Parameters

    • externaltargetObject: object
    • externaloptionalconstructorOpt: Function

    Returns void