Pular para o conteúdo principal

StarlightError

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

Properties

Constructors

constructor

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

    • message: string
    • response: Response

    Returns StarlightError

Properties

publicresponse

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