@sanity/scheduled-publishing
Version:
> [!IMPORTANT] > As of [v3.39.0](https://www.sanity.io/changelog/e6013ee5-8214-4e03-9593-f7b19124b8a3) of Sanity Studio, this plugin has been deprecated and the Scheduled Publishing functionality has been moved into the core studio package. > Read more an
32 lines (27 loc) • 895 B
text/typescript
import type {ClientError} from '@sanity/client'
import {FORBIDDEN_RESPONSE_TEXT} from '../constants'
// this is used in place of `instanceof` so the matching can be more robust and
// won't have any issues with dual packages etc
// https://nodejs.org/api/packages.html#dual-package-hazard
function isClientError(e: unknown): e is ClientError {
if (typeof e !== 'object') return false
if (!e) return false
return 'statusCode' in e && 'response' in e
}
export default function getErrorMessage(err: unknown): string {
let message
if (isClientError(err)) {
// The request was made and the server responded with a status code
if (err.response.statusCode === 403) {
message = FORBIDDEN_RESPONSE_TEXT
} else {
message = err.message
}
} else {
if (err instanceof Error) {
message = err.message
}
message = String(err)
}
return message
}