Skip to content

Commit

Permalink
Update compositor.json via compositor.io
Browse files Browse the repository at this point in the history
  • Loading branch information
cdimascio committed Aug 29, 2018
1 parent d23e053 commit c1f4b34
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion compositor.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"metadata": {
"source": "github.readme"
},
"html": "\n<p>Package for normalizing api errors using the following format:</p>\n<p><img src=\"https://github.com/cdimascio/wcp-errors/blob/master/assets/error.png?raw=true\"></p>\n<h2>Install</h2>\n<pre>npm install wcp-errors</pre><h2>Usage</h2>\n<pre><span class=\"hljs-keyword\">const</span> { notFound } = <span class=\"hljs-built_in\">require</span>(<span class=\"hljs-string\">&apos;wcp-errors&apos;</span>);\nbadRequest(<span class=\"hljs-string\">&apos;first name is required.&apos;</span>);</pre><h2>Examples (ExpressJS)</h2>\n<pre>app.get(<span class=\"hljs-string\">&apos;/not_found&apos;</span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function</span>(<span class=\"hljs-params\">req, res, next</span>) </span>{\n next(notFound());\n});\n\n<span class=\"hljs-comment\">// Bad request example</span>\napp.get(<span class=\"hljs-string\">&apos;/bad_request&apos;</span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function</span>(<span class=\"hljs-params\">req, res, next</span>) </span>{\n next(\n badRequest(<span class=\"hljs-string\">&apos;Eek! A bad request&apos;</span>, <span class=\"hljs-keyword\">new</span> <span class=\"hljs-built_in\">Error</span>(), {\n <span class=\"hljs-attr\">type</span>: <span class=\"hljs-string\">&apos;parameter&apos;</span>,\n <span class=\"hljs-attr\">name</span>: <span class=\"hljs-string\">&apos;Eek&apos;</span>,\n })\n );\n});\n\napp.get(<span class=\"hljs-string\">&apos;/multiple_errors&apos;</span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function</span>(<span class=\"hljs-params\">req, res, next</span>) </span>{\n next(\n badRequest(<span class=\"hljs-string\">&apos;Eek! A bad request&apos;</span>).add({\n <span class=\"hljs-attr\">code</span>: <span class=\"hljs-string\">&apos;bad_request&apos;</span>,\n <span class=\"hljs-attr\">message</span>: <span class=\"hljs-string\">&apos;:-(&apos;</span>,\n })\n );\n});\n\n<span class=\"hljs-comment\">// Throw! example</span>\napp.get(<span class=\"hljs-string\">&apos;/throws&apos;</span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function</span>(<span class=\"hljs-params\">req, res, next</span>) </span>{\n <span class=\"hljs-keyword\">throw</span> <span class=\"hljs-keyword\">new</span> <span class=\"hljs-built_in\">Error</span>(<span class=\"hljs-string\">&apos;Oh noes!&apos;</span>);\n});\n\n<span class=\"hljs-comment\">// Error handler</span>\napp.use(<span class=\"hljs-function\"><span class=\"hljs-keyword\">function</span>(<span class=\"hljs-params\">err, req, res, next</span>) </span>{\n <span class=\"hljs-keyword\">if</span> (err <span class=\"hljs-keyword\">instanceof</span> ApiError) {\n res.status(err.statusCode).json(err);\n } <span class=\"hljs-keyword\">else</span> {\n res.status(<span class=\"hljs-number\">500</span>).json(internalServerError(err.message, err));\n }\n});</pre><h2>Run the examples</h2>\n<ul>\n<li><code>cd example/express</code></li>\n<li><code>npm install</code></li>\n<li><code>npm start</code></li>\n</ul>\n<p>Open a browser and try:</p>\n<ul>\n<li><a href=\"http://localhost:3000/not_found\">http://localhost:3000/not_found</a></li>\n<li><a href=\"http://localhost:3000/bad_request\">http://localhost:3000/bad_request</a></li>\n<li><a href=\"http://localhost:3000/multiple_errors\">http://localhost:3000/multiple_errors</a></li>\n<li><a href=\"http://localhost:3000/throws\">http://localhost:3000/throws</a></li>\n</ul>\n<h2>APIs</h2>\n<h3>Basic</h3>\n<p>All basic Apis take the following three <strong><em>optional</em></strong> arguments:</p>\n<ul>\n<li><code>message</code>: a string describing the error</li>\n<li><code>error</code>: an <code>Error</code> object</li>\n<li><code>target</code>: an object with shape <code>{ type, name }</code></li>\n</ul>\n<h3>All APIs</h3>\n<pre>badRequest();\nconflict();\nforbidden();\ninternalServerError();\nmethodNotAllowed();\nnotAcceptable();\nnotFound();\nrequestEntityTooLarge();\nunAuthorized();\nunsupportedMediaType();</pre><p>Optionally, add additional errors to a wcp error</p>\n<pre><span class=\"hljs-comment\">// Create an error and add additional error(s) to the wcp error</span>\nbadRequest().add({\n code = <span class=\"hljs-string\">&apos;validation_error&apos;</span>, <span class=\"hljs-comment\">// optional</span>\n message = <span class=\"hljs-string\">&apos;last name required.&apos;</span>, <span class=\"hljs-comment\">// optional</span>\n target, <span class=\"hljs-comment\">// optional target</span>\n error <span class=\"hljs-comment\">// optional error object</span>\n})</pre><h3>Raw</h3>\n<p>The raw API is only necessary in circumstances where the <a href=\"#basic\">Basic</a> are not sufficient.</p>\n<pre> <span class=\"hljs-keyword\">const</span> { ApiError } = <span class=\"hljs-built_in\">require</span>(<span class=\"hljs-string\">&apos;wcp-errors&apos;</span>);\n\n<span class=\"hljs-comment\">// Manually create a new API error</span>\n<span class=\"hljs-keyword\">const</span> e = <span class=\"hljs-keyword\">new</span> ApiError({\n <span class=\"hljs-attr\">statusCode</span>: <span class=\"hljs-number\">409</span>,\n <span class=\"hljs-attr\">code</span>: <span class=\"hljs-string\">&apos;conflict&apos;</span>,\n message,\n error, <span class=\"hljs-comment\">// optional error</span>\n target, <span class=\"hljs-comment\">// optional target</span>\n}).add({\n code = <span class=\"hljs-string\">&apos;error&apos;</span>, <span class=\"hljs-comment\">// optional</span>\n message = <span class=\"hljs-string\">&apos;unxepected error 1&apos;</span>, <span class=\"hljs-comment\">// optional</span>\n target, <span class=\"hljs-comment\">// optional target</span>\n error <span class=\"hljs-comment\">// optional error object</span>\n}).add({\n code = <span class=\"hljs-string\">&apos;error&apos;</span>, <span class=\"hljs-comment\">// optional</span>\n message = <span class=\"hljs-string\">&apos;unxepected error 2&apos;</span>, <span class=\"hljs-comment\">// optional</span>\n target, <span class=\"hljs-comment\">// optional target</span>\n error <span class=\"hljs-comment\">// optional error object</span>\n})</pre><h2>TODO</h2>\n<ul>\n<li>Create basic api functions for all http errors</li>\n<li>Normalize basic apis with <code>add</code> api</li>\n<li><p>Create dedicated Express middleware, such that a user does not have to write the fallback error handler middleware.</p>\n<p>ex: (currently user&apos;s must create a fallback middleware similiar to the following)</p>\n<pre>app.use(<span class=\"hljs-function\"><span class=\"hljs-keyword\">function</span>(<span class=\"hljs-params\">err, req, res, next</span>) </span>{\n <span class=\"hljs-keyword\">if</span> (err <span class=\"hljs-keyword\">instanceof</span> ApiError) {\n res.status(err.statusCode).json(err);\n } <span class=\"hljs-keyword\">else</span> {\n res.status(<span class=\"hljs-number\">500</span>).json(internalServerError(err.message, err));\n }\n});</pre></li>\n</ul>\n<h2>Contributers</h2>\n<p>Contributers are welcome! Please submit a PR.</p>\n<h2>License</h2>\n<p>MIT</p>\n"
"html": "\n<p>Package for normalizing api errors using the following format:</p>\n<p><img src=\"https://github.com/cdimascio/wcp-errors/blob/master/assets/error.png?raw=true\"></p>\n<h2>Install</h2>\n<pre>npm install wcp-errors</pre><h2>Usage</h2>\n<pre><span class=\"hljs-keyword\">const</span> { notFound } = <span class=\"hljs-built_in\">require</span>(<span class=\"hljs-string\">&apos;wcp-errors&apos;</span>);\nbadRequest(<span class=\"hljs-string\">&apos;first name is required.&apos;</span>);</pre><h2>Examples (ExpressJS)</h2>\n<pre>app.get(<span class=\"hljs-string\">&apos;/not_found&apos;</span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function</span>(<span class=\"hljs-params\">req, res, next</span>) </span>{\n next(notFound());\n});\n\n<span class=\"hljs-comment\">// Bad request example</span>\napp.get(<span class=\"hljs-string\">&apos;/bad_request&apos;</span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function</span>(<span class=\"hljs-params\">req, res, next</span>) </span>{\n next(\n badRequest(<span class=\"hljs-string\">&apos;Eek! A bad request&apos;</span>, <span class=\"hljs-keyword\">new</span> <span class=\"hljs-built_in\">Error</span>(), {\n <span class=\"hljs-attr\">type</span>: <span class=\"hljs-string\">&apos;parameter&apos;</span>,\n <span class=\"hljs-attr\">name</span>: <span class=\"hljs-string\">&apos;Eek&apos;</span>,\n })\n );\n});\n\napp.get(<span class=\"hljs-string\">&apos;/multiple_errors&apos;</span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function</span>(<span class=\"hljs-params\">req, res, next</span>) </span>{\n next(\n badRequest(<span class=\"hljs-string\">&apos;Eek! A bad request&apos;</span>).add({\n <span class=\"hljs-attr\">code</span>: <span class=\"hljs-string\">&apos;bad_request&apos;</span>,\n <span class=\"hljs-attr\">message</span>: <span class=\"hljs-string\">&apos;:-(&apos;</span>,\n })\n );\n});\n\n<span class=\"hljs-comment\">// Throw! example</span>\napp.get(<span class=\"hljs-string\">&apos;/throws&apos;</span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function</span>(<span class=\"hljs-params\">req, res, next</span>) </span>{\n <span class=\"hljs-keyword\">throw</span> <span class=\"hljs-keyword\">new</span> <span class=\"hljs-built_in\">Error</span>(<span class=\"hljs-string\">&apos;Oh noes!&apos;</span>);\n});\n\n<span class=\"hljs-comment\">// Error handler</span>\napp.use(<span class=\"hljs-function\"><span class=\"hljs-keyword\">function</span>(<span class=\"hljs-params\">err, req, res, next</span>) </span>{\n <span class=\"hljs-keyword\">if</span> (err <span class=\"hljs-keyword\">instanceof</span> ApiError) {\n res.status(err.statusCode).json(err);\n } <span class=\"hljs-keyword\">else</span> {\n res.status(<span class=\"hljs-number\">500</span>).json(internalServerError(err.message, err));\n }\n});</pre><h2>Run the examples</h2>\n<ul>\n<li><code>cd example/express</code></li>\n<li><code>npm install</code></li>\n<li><code>npm start</code></li>\n</ul>\n<p>Open a browser and try:</p>\n<ul>\n<li><a href=\"http://localhost:3000/not_found\">http://localhost:3000/not_found</a></li>\n<li><a href=\"http://localhost:3000/bad_request\">http://localhost:3000/bad_request</a></li>\n<li><a href=\"http://localhost:3000/multiple_errors\">http://localhost:3000/multiple_errors</a></li>\n<li><a href=\"http://localhost:3000/throws\">http://localhost:3000/throws</a></li>\n</ul>\n<h2>APIs</h2>\n<h3>Basic</h3>\n<p>All basic Apis take the following three <strong><em>optional</em></strong> arguments:</p>\n<ul>\n<li><code>message</code>: a string describing the error</li>\n<li><code>error</code>: an <code>Error</code> object</li>\n<li><code>target</code>: an object with shape <code>{ type, name }</code></li>\n</ul>\n<h3>All APIs</h3>\n<pre>badRequest();\nconflict();\nforbidden();\ninternalServerError();\nmethodNotAllowed();\nnotAcceptable();\nnotFound();\nrequestEntityTooLarge();\nunAuthorized();\nunsupportedMediaType();</pre><p>Optionally, add additional errors to a wcp error</p>\n<pre><span class=\"hljs-comment\">// Create an error and add additional error(s) to the wcp error</span>\nbadRequest().add({\n code = <span class=\"hljs-string\">&apos;validation_error&apos;</span>, <span class=\"hljs-comment\">// optional</span>\n message = <span class=\"hljs-string\">&apos;last name required.&apos;</span>, <span class=\"hljs-comment\">// optional</span>\n target, <span class=\"hljs-comment\">// optional target</span>\n error <span class=\"hljs-comment\">// optional error object</span>\n})</pre><h3>Raw</h3>\n<p>The raw API is only necessary in circumstances where the <a href=\"#basic\">Basic</a> are not sufficient.</p>\n<pre> <span class=\"hljs-keyword\">const</span> { ApiError } = <span class=\"hljs-built_in\">require</span>(<span class=\"hljs-string\">&apos;wcp-errors&apos;</span>);\n\n<span class=\"hljs-comment\">// Manually create a new API error</span>\n<span class=\"hljs-keyword\">const</span> e = <span class=\"hljs-keyword\">new</span> ApiError({\n <span class=\"hljs-attr\">statusCode</span>: <span class=\"hljs-number\">409</span>,\n <span class=\"hljs-attr\">code</span>: <span class=\"hljs-string\">&apos;conflict&apos;</span>,\n message,\n error, <span class=\"hljs-comment\">// optional error</span>\n target, <span class=\"hljs-comment\">// optional target</span>\n}).add({\n code = <span class=\"hljs-string\">&apos;error&apos;</span>, <span class=\"hljs-comment\">// optional</span>\n message = <span class=\"hljs-string\">&apos;unxepected error 1&apos;</span>, <span class=\"hljs-comment\">// optional</span>\n target, <span class=\"hljs-comment\">// optional target</span>\n error <span class=\"hljs-comment\">// optional error object</span>\n}).add({\n code = <span class=\"hljs-string\">&apos;error&apos;</span>, <span class=\"hljs-comment\">// optional</span>\n message = <span class=\"hljs-string\">&apos;unxepected error 2&apos;</span>, <span class=\"hljs-comment\">// optional</span>\n target, <span class=\"hljs-comment\">// optional target</span>\n error <span class=\"hljs-comment\">// optional error object</span>\n})</pre><h2>TODO</h2>\n<ul>\n<li>Create basic api functions for all http errors</li>\n<li>Normalize basic apis with <code>add</code> api</li>\n<li><p>Create dedicated Express middleware, such that a user does not have to write the fallback error handler middleware.</p>\n<p><strong>ex:</strong></p>\n<p><em>currently user&apos;s must create a fallback middleware similiar to the following</em></p>\n<pre>app.use(<span class=\"hljs-function\"><span class=\"hljs-keyword\">function</span>(<span class=\"hljs-params\">err, req, res, next</span>) </span>{\n <span class=\"hljs-keyword\">if</span> (err <span class=\"hljs-keyword\">instanceof</span> ApiError) {\n res.status(err.statusCode).json(err);\n } <span class=\"hljs-keyword\">else</span> {\n res.status(<span class=\"hljs-number\">500</span>).json(internalServerError(err.message, err));\n }\n});</pre></li>\n</ul>\n<h2>Contributers</h2>\n<p>Contributers are welcome! Please submit a PR.</p>\n<h2>License</h2>\n<p>MIT</p>\n"
},
{
"component": "footer",
Expand Down

0 comments on commit c1f4b34

Please sign in to comment.