{"id":37718007,"url":"https://github.com/tchar/error-factory-js","last_synced_at":"2026-01-16T13:29:54.612Z","repository":{"id":57226734,"uuid":"114481523","full_name":"tchar/error-factory-js","owner":"tchar","description":"An error-factory JavaScript module for creating errors and handling them in a dynamic way","archived":false,"fork":false,"pushed_at":"2018-04-17T11:21:44.000Z","size":72,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-12T03:39:23.692Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tchar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-16T18:21:31.000Z","updated_at":"2018-04-16T09:31:36.000Z","dependencies_parsed_at":"2022-08-24T15:51:02.508Z","dependency_job_id":null,"html_url":"https://github.com/tchar/error-factory-js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tchar/error-factory-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tchar%2Ferror-factory-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tchar%2Ferror-factory-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tchar%2Ferror-factory-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tchar%2Ferror-factory-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tchar","download_url":"https://codeload.github.com/tchar/error-factory-js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tchar%2Ferror-factory-js/sbom","scorecard":{"id":870592,"data":{"date":"2025-08-11","repo":{"name":"github.com/tchar/error-factory-js","commit":"f1520a4e1d759965a6a358f51c307e41d55b97fc"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.4,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":5,"reason":"5 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-24T04:05:41.454Z","repository_id":57226734,"created_at":"2025-08-24T04:05:41.454Z","updated_at":"2025-08-24T04:05:41.454Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28479033,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-16T13:29:54.533Z","updated_at":"2026-01-16T13:29:54.604Z","avatar_url":"https://github.com/tchar.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# error-factory-js\nA JavaScript Factory for creating and handling errors\n\nThis module can be used to create custom JavaScript Errors and handle them.\n\nWhen creating an Error a function can be passed to it, so when catching it\nyou can handle it by calling error.handle(args);\n\nAlso this module knows which Errors are generated by it so you can create generic\nhandlers for Errors that were created by it.\n\nHandling Errors is simple and can be either sync or async (Using promises) by using the ErrorFactory's\nmethods (see Examples)\n\n# Documentation\nThis module supports a simple mode to create errors and an extended mode to access the ErrorFactory and its methods\n\nThe simple mode can be accessed by using\n```javascript\nconst ErrorFactory = require('error-factory-js');\nvar MyError = ErrorFactory('MyError', callback);\nthrow MyError('Some messsage', extras);\n```\n\nIn this context the callback and extras are optional, though\nthey can be accessed by using\n```error.handle()``` and ```error.extras```\n\nThe extended mode can be accessed by using\n```javascript\nconst ErrorFactory = require('error-factory-js');\n```\nand call ```ErrorFactory().someMethod()``` or ```ErrorFactory.someMethod()``` to access the method\n\nThe supported methods are:\n### setPromiseLibrary(promiseLib)\nThis method sets the promise library to be used for handleAsync\n```javascript\nconst ErrorFactory = require('error-factory-js')\nErrorFactory.setPromiseLibrary(Promise) // use builtin promise library\n```\n### create(name, msg, callback, extras)\nThis method is equivalent to the simple mode's error creation\n```javascript\ntry{\n    throw ErrorFactory.create('MyError', 'Some Message', callback, extras);\n} catch(err){\n    err.message // The error message\n    err.handle() // To call the handle function\n    err.extras // The extras\n}\n```\n### exists(error)\nThis method returns true if the error was created by this ErrorFactory, false otherwise\n```javascript\ntry {\n    throw ErrorFactory.create('MyError', 'Some Message', callback, extras);\n} catch(err){\n    ErrorFactory.exists(err) // This is true\n}\n```\n### canHandle(error)\nThis method returns true if a callback was specified when creating an error, false otherwise\n```javascript\ntry{\n    var MyError = ErrorFactory('MyError', callback)\n    throw MyError('Some Message');\n} catch(err){\n    ErrorFactory.canHandle(err) // This is true\n}\n```\n### handle(error)\nThis method handles the error and returns true if the error was handled false otherwise\n```javascript\ntry{\n    var MyError = ErrorFactory('MyError', callback)\n    throw MyError('Some Message');\n} catch(err){\n    ErrorFactory.handle(err) // This is true and error was handled using callback\n}\n```\n### handleAsync(error)\nThis method is like handle() but handles the error using Promises\n```javascript\ntry{\n    var MyError = ErrorFactory('MyError', callback)\n    throw MyError('Some Message');\n} catch(err){\n    ErrorFactory.handleAsync(err) // This is true and error will be handled using callback\n}\n```\n### expressHandler()\nThis method is a generic express handler that returns a function with a signature (err, req, res, next)\nThe express handler takes a javascript object as options.\nOptions ```{handleAsync: boolean}``` if you want to use handle or handleAsync, default ```false```\nSee examples below in how to use it\n```javascript\n\nvar callback = function(err, req, res, next){\n    console.log(this === err) // prints true\n    res.send(err.message)\n}\n\napp.use('/' function(req, res, next){\n    next(ErrorFactory.create('MyError', callback));\n})\n\napp.use(ErrorFactory.expressHandler());\n\napp.use(function(err, req, res, next)){\n    // Handle other errors not created by this Factory\n}\n```\n### remove(error)\nRemoves an error from this factory, so now it can not be handled by handle(), handleAsync() etc.\n```javascript\ntry{\n    var MyError = ErrorFactory('MyError', callback)\n    throw MyError('Some Message');\n} catch(err){\n    ErrorFactory.remove(err);\n    ErrorFactory.exists(err) // This is false\n    ErrorFactory.canHandle(err) // This is false\n    ErrorFactory.handle(err) // This is false\n    ErrorFactory.handleAsync(err) // this is false\n}\n```\n### flush()\nRemoves all errors from this factory\n```javascript\ntry{\n    var MyError = ErrorFactory('MyError', callback)\n    throw MyError('Some Message');\n} catch(err){\n    ErrorFactory.flush();\n    ErrorFactory.exists(err) // This is false\n    ErrorFactory.canHandle(err) // This is false\n    ErrorFactory.handle(err) // This is false\n    ErrorFactory.handleAsync(err) // this is false\n}\n```\n### addHandler(name, handler) / getHandler(name)\nSets/gets a handler with a name for later use\nFollowing code is for express, but can be used for other instances too.\n```javascript\nconst app = require('express')();\nconst ErrorFactory = require('error-factory-js');\napp.use('/' function(req, res, next){\n    next(ErrorFactory.create('MyError', callback));\n})\n\nvar MyHandler = function(err, req, res, next){\n    // implement something\n}\n\n\nErrorFactory.addHandler('SomeHandler', MyHandler);\n\napp.use(ErrorFactory.getHandler('SomeHandler'));\n\napp.use(function(err, req, res, next)){\n    // Handle other errors not created by this Factory\n}\n```\n### getErrorConstructor(name)\nGets the constructor of a specified error by name.\nThis is useful when creating errors through the ErrorFactory `create()`\nmethod.\n```javascript\ntry{\n    throw ErrorFactory.create('MyError', 'Some Message', callback, extras);\n} catch(err){\n    console.log(err instanceof ErrorFactory.getErrorConstructor('MyError')) // This is true\n    err.message // The error message\n    err.handle() // To call the handle function\n    err.extras // The extras\n}\n```\n\n# Tests\nYou can run tests with npm test.\n\nYou must install the dev dependencies though:\n\nmocha\n\nshould\n\n# Examples\n\nYou can find examples under the examples folder.\n\nBelow are some examples of error-factory-js usage.\n\n## Simple Example\n```javascript\nconst ErrorFactory = require('error-factory-js');\n\ntry{\n    var MyError = ErrorFactory('MyError');\n    throw MyError('This is an error');\n} catch (error){\n    console.log(error.message); // Prints This is an error\n}\n```\n## Simple Example by using ErrorFactory's create method\n```javascript\nconst ErrorFactory = require('error-factory-js');\n\ntry{\n    throw ErrorFactory.create('MyError', 'This is some err');\n} catch (error){\n    console.log(error.message); // Prints This is some err\n}\n```\n## Simple Example with handle function\n```javascript\nconst ErrorFactory = require('error-factory-js');\n\nvar handleFunc = function(){\n    console.log(this.message) // This refers to the error\n                              // If called from error context\n}\n\ntry{\n    var MyError = ErrorFactory('MyError', handleFunc);\n    throw MyError(\"Some other message\");\n} catch (error){\n    error.handle(); // Will print Some other message\n}\n```\n## Simple Example with handle function by using ErrorFactory's sync handle\n```javascript\nconst ErrorFactory = require('error-factory-js');\n\nvar handleFunc = function(){\n    console.log(this.message) // This refers to the error\n}\n\ntry{\n    var MyError = ErrorFactory('MyError', handleFunc);\n    throw MyError(\"Some other message too\");\n} catch (error){\n    if (ErrorFactory.handle(error)){\n        console.log('Error Handled')\n    } else {\n        console.log('Error not handled');\n        // Handle error manually in case handleFunc was not defined\n        // Or the error was not created by this ErrorFactory\n    }\n}\n\n// The output of this should be\n// Some other message too\n// Error Handled\n```\n## Simple Example with handle function by using ErrorFactory's sync handle\n```javascript\nconst ErrorFactory = require('error-factory-js');\n\nvar handleFunc = function(){\n    console.log(this.message) // This refers to the error\n}\n\ntry{\n    var MyError = ErrorFactory('MyError', handleFunc);\n    throw MyError(\"Another other message\");\n} catch (error){\n    if (ErrorFactory.handleAsync(error)){\n        console.log('Error Handled')\n    } else {\n        console.log('Error not handled');\n        // Handle error manually in case handleFunc was not defined\n        // Or the error was not created by this ErrorFactory\n    }\n}\n\n// The output of this should be\n// Error Handled\n// Another other message\n```\n## Simple Example with Express and using ErrorFactory's handle/handleAsync\n```javascript\nconst app = require('express')();\nconst ErrorFactory = require('error-factory-js');\n\nvar func = function(req, res, next){\n    res.status(500).send(this.message);\n}\n\napp.use('/', function(req, res, next){\n    next(ErrorFactory.create('CustomError', 'Hey something went wrong', func));\n    // or\n    var MyError = ErrorFactory('CustomError', func);\n    next(MyError('Hey something went wrong'));\n});\n\napp.use(function(err, req, res, next){\n    if (!ErrorFactory.handleAsync(err, req, res, next)){\n        // handle the error manually\n    }\n});\n\n// This code will send a status 500 with message 'Hey something went wrong'\n```\n## Simple Example with Express and using ErrorFactory's expressHandler\n```javascript\nconst app = require('express')();\nconst ErrorFactory = require('error-factory-js');\n\nvar func = function(req, res, next){\n    res.status(500).send(this.message);\n}\n\napp.use('/', function(req, res, next){\n    next(ErrorFactory.create('CustomError', 'Hey something went wrong', func));\n    // or\n    var MyError = ErrorFactory('CustomError', func);\n    next(MyError('Hey something went wrong'));\n});\n\napp.use(ErrorFactory.expressHandler({handleAsync: true}));\n// If the error can be handled by the express handler next() is called after\n// handling the error else next(err) is called \n// so be sure to add this before the generic error handler\n// and not use any res.send below this point\n\napp.use(function(err, req, res, next){\n    // Handle the other errors;\n});\n\n// This code will send a status 500 with message 'Hey something went wrong'\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftchar%2Ferror-factory-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftchar%2Ferror-factory-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftchar%2Ferror-factory-js/lists"}