export const pluginPrefix = 'gatsby-source-sanity' ; export function prefixId ( id ) { return `${ pluginPrefix }_${ id }` ; } enum ReporterLevel { Error = 'ERROR' } enum ReporterCategory { User = 'USER' , ThirdParty = 'THIRD_PARTY' , System = 'SYSTEM' } export const ERROR_CODES = { UnsupportedGatsbyVersion : '10000' , SchemaFetchError : '10001' , MissingProjectId : '10002' , MissingDataset : '10002' , InvalidToken : '10003' , ExpiredToken : '10004' , WrongProjectToken : '10005' , } ; export const ERROR_MAP = { [ ERROR_CODES . UnsupportedGatsbyVersion ] : { text : ( context ) => context . sourceMessage , level : ReporterLevel . Error , category : ReporterCategory . User , } , [ ERROR_CODES . SchemaFetchError ] : { text : ( context ) => context . sourceMessage , level : ReporterLevel . Error , category : ReporterCategory . ThirdParty , } , [ ERROR_CODES . MissingProjectId ] : { text : ( context ) => context . sourceMessage , level : ReporterLevel . Error , category : ReporterCategory . User , } , [ ERROR_CODES . MissingDataset ] : { text : ( context ) => context . sourceMessage , level : ReporterLevel . Error , category : ReporterCategory . User , } , [ ERROR_CODES . InvalidToken ] : { text : ( context ) => context . sourceMessage , level : ReporterLevel . Error , category : ReporterCategory . User , } , [ ERROR_CODES . ExpiredToken ] : { text : ( context ) => context . sourceMessage , level : ReporterLevel . Error , category : ReporterCategory . User , } , [ ERROR_CODES . WrongProjectToken ] : { text : ( context ) => context . sourceMessage , level : ReporterLevel . Error , category : ReporterCategory . User , } , } ; export const SANITY_ERROR_CODE_MAP = { 'SIO-401-ANF' : ERROR_CODES . InvalidToken , 'SIO-401-AWH' : ERROR_CODES . WrongProjectToken , 'SIO-401-AEX' : ERROR_CODES . ExpiredToken , } ; export const SANITY_ERROR_CODE_MESSAGES = { 'SIO-401-ANF' : 'The token specified is not valid or has been deleted' , 'SIO-401-AWH' : 'The token specified does not belong to the configured project' , 'SIO-401-AEX' : 'The token specified is expired - use API tokens instead of user tokens to prevent this from happening' , } ; export class ErrorWithCode extends Error { public code ? : string | number ; constructor ( message , code ? ) { super ( message ) ; this . code = code ; } }