1.0.16 • Published 1 year ago

@dramaorg/tempore-culpa v1.0.16

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

@dramaorg/tempore-culpa

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 @dramaorg/tempore-culpa

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('@dramaorg/tempore-culpa')
const CustomError = createError('ERROR_CODE', 'Hello')
console.log(new CustomError()) // error.message => 'Hello'

How to use an interpolated string:

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

How to add cause:

const createError = require('@dramaorg/tempore-culpa')
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.

glacierdescriptiontypescriptsidemkdirptoobjectoncees2018sameValueZeroconfig.gitignoredataredactESnexteast-asian-widthecmascriptwafproxyglobalThises6ignoredotenvoptimistloggerfunction.lengthutilitiesassignhelperrdsObject.valuesutilsparenthardlinksbuffersSymbol.toStringTaghooksregexpcloudtrailsinatraserializerSetECMAScript 2016accessibilitysearchmonoreposwfECMAScript 6mruhigher-orderes-shimsshebangES2018fastcopymapreducespringfpsfile systembusyspawnkeysimpledbreversewgetcolumnsSystem.globalgroupByassertionfigletWebSocketspopmotionvalidglobmochaemojiqsredirectbinpromiselocaltouchjson-schema-validationArray.prototype.findLastIndexclassnamesmkdirpicomatchtranspilerschemavalidationcircularcharactergetopt-0dateeslint-plugindeterministiclockfilespeedprogresssetPrototypeOfletyupjapanesereadablestreamRegExp.prototype.flagsSymboliteratestyleguidetrimRightTypeBoxzxlengthJSONautoprefixerreducermulti-packageiteratorObjectdirWeakSetpackagesgraphqlFloat32ArraysetImmediatewalkingwalkenvMicrosoftregexJSON-Schemaastasyncoutputbinaryworkerrework_.extendescapequeueMicrotaskObject.isrsscollection.es6findLastIndexreact-hookslocationpluginArray.prototype.flattenmatchcjkstyleWeakMapjsonzodreuseslotjson-schemasomepathexecutedom-testing-libraryworkflowlanguageprettymanipulationObject.getPrototypeOftestingbddstoragegatewayes-shim APIObservablesprefixinstallclientcolumnrulesvalidatorl10ninstallerforkreact animationcallimportECMAScript 2019endpointweaksetequalitya11yappESrmdirquotetranspilecloudformationtyped arrayuser-streamsiamjsonschemababel-corecolourbindstringsubprocessrequirecall-bindavaObservablecodesjsxtacitdebugcloudwatchasciiwindowsymbolsreadfull-widthchinesereact poseBigUint64ArrayassertsfullwidthtypedarrayshamnameconcatMapform-validationrobustconsumeECMAScriptgetcompilerlistenerstypeofterminalpinoparserformfeedhtmles2016deletees2017shellkoreanimmerfindramdavarsesparentspyyamlECMAScript 2022lookarrayarraysreadableselftoReversedmatchAllequalseteffect-tseveryES6fastRxJS__proto__awesomesauceguidboundtapepnpm9shimtakefunctionsfilterfastclonehasOwnPropertyjsdiffforEachmodulejsdombrowserslistECMAScript 5xtermflatArray.prototype.includesroutebannerruntimeReflect.getPrototypeOfvarnegative zeroregular expressionseslinttransformes-abstractdeepisConcatSpreadablecolorsprivate datareact-hook-formsymlinkses7typedpackage.jsonprocessconfigurableemrcharacterscommand-lineArray.prototype.flatMapwritableaccessorprotocol-bufferslrucollectionxmlfile@@toStringTagpackage managerRegExp#flagsargumentzeroassertgenericsbytetoolkitdescriptorsefficientarktypeReactiveExtensionspropertiescensorhookformcommandInt8Arrayoptionphonecore-jsawsArray.prototype.flattoSortedStyleSheettap256ES7flattengdprspinnerautoscalingdeep-clonereactpropertyspecstringifysymbolreduxenvironmentssyntaxerror3deventstypeerrorregular-expressionclass-validatorextendrestReactiveXchannelanimationmapInt16ArraytextrangeerrorgetPrototypeOffunctionalexpresstrimwaapigetOwnPropertyDescriptorMapwaitenumerableowninvariantpostcss-plugingetterposebeanstalkentriesexecinspecttslibutilsessortedlibphonenumberurlpushs3starterString.prototype.matchAllECMAScript 2018fastifyhashprivatetransportUint16ArrayrapidES2019uuidObject.definePropertycache.envfromObject.assigntypesidleelasticachetoStringTagreversedgitignoreloggingrestfulECMAScript 2017loadingelectronUint8ArraycoverageconsolecloudfrontstreamfsprotobufsqsflagspinnersjestelbArray.prototype.containsmakesnswarningtimedefineec2rgbdomstreamsObject.keysfantasy-landglobalssource mapYAMLdescriptorinstrumentationcurlnopeECMAScript 2021superagentio-tsreal-timestylesregular expressionrmmanagervpcIteratorbundlergroupkarmaArray.prototype.findLasthelperses8ajvrecursiveemitshrinkwrapAsyncIteratorUint32ArrayatomiedynamodbmobilediffqueuefpintrinsicES2022xhrerrorpatchcssansiclassescode pointsECMAScript 2020routercss-in-jsArrayBuffer.prototype.slicerm -rfbufferpackagecallbackES3definePropertyespreejoirandompositivereact-testing-libraryECMAScript 2015eventDispatchercopyomitRxsharedmomentsetterdataViewbundlingpropobjES2021[[Prototype]]eslintconfigamazonECMAScript 2023Arrayin
1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

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