1.1.3 • Published 1 year ago

@hishprorg/et-illo v1.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@hishprorg/et-illo

CI NPM version js-standard-style

A small utility, used by Fastify itself, for generating consistent error objects across your codebase and plugins.

Install

npm i @hishprorg/et-illo

Usage

The module exports a function that you can use for consistent error objects, it takes 4 parameters:

createError(code, message [, statusCode [, Base]])
  • code (string, required) - The error code, you can access it later with error.code. For consistency, we recommend prefixing plugin error codes with FST_
  • message (string, required) - The error message. You can also use interpolated strings for formatting the message.
  • statusCode (number, optional) - The status code that Fastify will use if the error is sent via HTTP.
  • Base (ErrorConstructor, optional) - The base error object that will be used. (eg TypeError, RangeError)
const createError = require('@hishprorg/et-illo')
const CustomError = createError('ERROR_CODE', 'Hello')
console.log(new CustomError()) // error.message => 'Hello'

How to use an interpolated string:

const createError = require('@hishprorg/et-illo')
const CustomError = createError('ERROR_CODE', 'Hello %s')
console.log(new CustomError('world')) // error.message => 'Hello world'

How to add cause:

const createError = require('@hishprorg/et-illo')
const CustomError = createError('ERROR_CODE', 'Hello %s')
console.log(new CustomError('world', {cause: new Error('cause')})) 
// error.message => 'Hello world'
// error.cause => Error('cause')

TypeScript

It is possible to limit your error constructor with a generic type using TypeScript:

const CustomError = createError<[string]>('ERROR_CODE', 'Hello %s')
new CustomError('world')
//@ts-expect-error
new CustomError(1)

License

Licensed under MIT.

bufferArray.prototype.flatMapargvserializeincludescharacterlastcodesmkdirseventEmitterTypedArraymodulesloggingfunctionselectronworkflowreplayprotobufFunction.prototype.nameshrinkwrapargsObject.assignstablecompile lessdateECMAScript 5ECMAScript 2016reduxfantasy-landbinariesless.jsa11yfast-copyconfigurablebddbytepackage.jsongradients css3ECMAScript 3hookformstreamsconcatredux-toolkitpureflatMapchromeloadingutilityECMAScript 6arktypeoperating-systempicomatchWeakSetmockfpsES6execfilecolumnsstylesregexpinvariantinstallposecall-bounddeeploggeriterationbeanstalkArrayBufferexecgraphqlassertionWeakMapreact-hook-formpreprocessorremovecryptlinkchineselockfilefullwidth0bundlingponyfillwafECMAScript 2017robustsafestringifierawesomesaucesnsfindbrowserutilitiesespreeextendtacitschemegetoptyupregular expressiones7internalformattingcolumnsettersequenceES8threeshimtrimEndbindfpglobrequestReactiveExtensionsRFC-6455ECMAScript 7resolveparsecloudfrontUnderscoretoStringTagmatcheshasOwnreact animationsymbolwriteObject.keyses-shimsInt16ArrayObject.entriesECMAScripttranspilercss variableYAMLvestgroupes2017patchsortoptimistnested cssownArray.prototype.flattencryptoformserializerprettymatchqueueMicrotasklogcloudsearchproxyHyBiomitbootstrap lessinpropertytrimStartchaiinputmonorepogetOwnPropertyDescriptorimmerimportpinofixed-widthprotopropcss lessdropoptiontoolssymbolsmakejwtzxpersistentqueryyamlfunctionaldires8warningjson-schema-validationbrowserlistphoneschemaquoteless compilersomeendpointdatastructurehashES5statusfswhatwgec2getPrototypeOfpluginvalueconsolecloudformation.envopensslspeedloadbalancingenvironmentcoreECMAScript 2019fast-clonenumberqsvpcES7deterministicsettingstypeofmoveregexdom-testing-libraryes5variablesstyled-componentsinterruptsshebangreusedataViewworkerObjectmruoncesigtermfunction.lengthobjecttouchclivalidchildroutingelbstreamminimalESnextarttoArrayReactiveXfiltereffect-tsrangeerrordomboundpredictableelasticachecloudtrailpathtyped arraybincopyscheme-validationweakmapbabel-coreintrinsiclengthvaluesjson-schema-validatornpmignoreSystem.globaleslintconfigcompileriteratorobjecmascriptpostcss-pluginECMAScript 2015metadatacolorArrayUint16ArrayES2018arraysserverprivate dataform-validation-0ramdafastcloneRxUint8ClampedArrayhotdeletemulti-packageMicrosoftjsonoutputsetImmediateroute53nativeshamastredirectmatchAllgitignorebanneridlespinnerreact posebusymkdirlazycloneJSON-SchemaclassnamesredacttexteverytrimESpushcoerciblestoragegatewayless mixinslintsharedpopmotionSymbolcolorsfile systemdayjsdescriptionswfapollotelephoneArrayBuffer.prototype.sliceArray.prototype.filterrdsiteratefigletstylesheeteventDispatcherentriesserializationjsdiffflatzerochromiumnpmnegativejavascriptconfigcommandtypeerrorspawngradients csstranspileprunehttpsforkhas-ownRxJStrimLeftemrcurriedeslint-pluginprivateECMAScript 2022i18nlrutostringtaghelperreact-componentterminalunicodecensorformsPushpromiseassignstatenodedeepcloneparserreal-timemergeURLSearchParamsfastifyequalitysqscallencryptionviewbcryptTypeBoxcjkstylingutilruntimeless csstesttypescriptnegative zeroerrorES2022sameValueZerodeep-copyjsdomcallboundcallbackCSSStyleDeclarationhigher-ordertraversespecgetintrinsicReflect.getPrototypeOfimmutableutil.inspectbinaryes6signalsvalidatehttpacornObservablestarteransienvassertsoffsetpasswordObject.getPrototypeOfjson-schemacallbindescapeArray.prototype.containsxtermfront-endstylelanguagesidegestureslocationairbnbES2020reactliveshellslotuploadajaxcreatetimeenderkinesisimportexportgetSymbol.toStringTagpositiveassertsignalrapid$.extendfetchtakemake dirhasOwnPropertyoptimizer.gitignoredragtoolkitwindowsJSONindicatorArray.prototype.flatweaksetuser-streamstypeisidentifierspropertiesstatelesstoobjectagentreact-hooksString.prototype.matchAllprogresslinuxvisualfileperformantxhrWebSocketsInt8ArraysymlinksvarsES2015helpers@@toStringTaginstallerdefinePropertyWebSocketvalidatorcontainsmapanimationstringsyntaxfromdefinepoint-freeamazonsignedstructuredCloneforEachclientjses2018pipeflagwalkwhichcompareasciiUint32ArrayinspectbrowserslistprototypeFloat32ArraysliceCSSexit-codeharmonyequalexpressframerawstestingtypesRegExp#flagsemitkeysflattendependencieses2015concatMapttycore-jsPromiseObject.defineProperty_.extendes2016routedeepcopyl10nvariables in csscss-in-jsArray.prototype.findLastgdprStreamreact-testing-librarymixinsgenericsconstutilsajvdescriptorsapisortedjsonschemahasquerystringeventsarrayback-endrecursivesesqueuetslibpolyfillcirculareast-asian-widthmomentStreamssyntaxerrorrgbfulltypesafeworkspace:*keyio-tsjshintpyyamlsetPrototypeOfasyncrulespackagesmkdirphardlinkscall-bindwaapienumerable3dtypedarrayObject.islessdatanamesstyleguideIteratorwindowaccessibilityfluxprefixES2021efficientUint8Arrayerror-handlingcloudwatchES2023MapES3joiObject.valuesinferencegettersymlinkSetString.prototype.trimfast-deep-clonefindLastIndexES2016[[Prototype]]tddnodejsregular-expressionchannelnameURLArray.prototype.includesisConcatSpreadablefunctionlesscssconsumesubprocesstypedglobalThis__proto__jsxdiffsigintrequireargumentinternal slotauthmockingpreserve-symlinksStyleSheetservicelibphonenumberexecutejapaneseglobalsvarwgetdependency managernopedataviewES2019curl256tc39byteOffsetsuperstructclassnameInt32Arrayextradeep-clonefull-widthletcomputed-typesselfclass-validatorpackage managerfindLastcollectioncommand-lineclassesbyteLengthspinnerswidthsetiam
1.1.3

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago