import { JSONObject } from "./types" ; public export const SkygearErrorNames = { BadRequest : "BadRequest" , Invalid : "Invalid" , Unauthorized : "Unauthorized" , Forbidden : "Forbidden" , NotFound : "NotFound" , AlreadyExists : "AlreadyExists" , TooManyRequest : "TooManyRequest" , InternalError : "InternalError" , ServiceUnavailable : "ServiceUnavailable" } as const ; public export type SkygearErrorName = ( typeof SkygearErrorNames ) [ keyof ( typeof SkygearErrorNames ) ] ; public export class CancelError extends Error { } public export const CANCEL = new CancelError ( ) ; remarks public export class SkygearError extends Error { remarks See  SkygearErrorNames for possible values.
     * New error names may be added in future.
      name : string ; remarks Error messages are provided for convenience, and not stable APIs;
     * Consumers should use  SkygearError . name or
     *  SkygearError . reason to distinguish between different errors.
      message ! : string ; /**
     * Error reason.
     */ reason : string ; /**
     * Additional error information.
     */ info ? : JSONObject ; constructor ( message , name , reason , info ? ) { super ( message ) ; this . name = name ; this . reason = reason ; this . info = info ; } } public export function decodeError ( err ? ) { if ( err != null && ! ( err instanceof Error ) && typeof err . name === "string" && typeof err . reason === "string" && typeof err . message === "string" ) { return new SkygearError ( err . message , err . name , err . reason , err . info ) ; } if ( err instanceof Error ) { return err ; } if ( err != null && typeof err . message === "string" ) { return new Error ( err . message ) ; } if ( err != null && typeof err . toString === "function" ) { return new Error ( err . toString ( ) ) ; } return new Error ( String ( err ) ) ; }