\href{https://npmjs.org/package/http-errors}{\texttt{ }} \href{https://npmjs.org/package/http-errors}{\texttt{ }} \href{https://nodejs.org/en/download/}{\texttt{ }} \href{https://travis-ci.org/jshttp/http-errors}{\texttt{ }} \href{https://coveralls.io/r/jshttp/http-errors}{\texttt{ }}

Create HTTP errors for Express, Koa, Connect, etc. with ease.\hypertarget{md_sfcode_node_modules_serve_index_node_modules_http_errors_README_autotoc_md26844}{}\doxysection{Install}\label{md_sfcode_node_modules_serve_index_node_modules_http_errors_README_autotoc_md26844}
This is a \href{https://nodejs.org/en/}{\texttt{ Node.\+js}} module available through the \href{https://www.npmjs.com/}{\texttt{ npm registry}}. Installation is done using the \href{https://docs.npmjs.com/getting-started/installing-npm-packages-locally}{\texttt{ {\ttfamily npm install} command}}\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm install http-\/errors }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_serve_index_node_modules_http_errors_README_autotoc_md26845}{}\doxysection{Example}\label{md_sfcode_node_modules_serve_index_node_modules_http_errors_README_autotoc_md26845}

\begin{DoxyCode}{0}
\DoxyCodeLine{var createError = require('http-\/errors')}
\DoxyCodeLine{var express = require('express')}
\DoxyCodeLine{var app = express()}
\DoxyCodeLine{}
\DoxyCodeLine{app.use(function (req, res, next) \{}
\DoxyCodeLine{  if (!req.user) return next(createError(401, 'Please login to view this page.'))}
\DoxyCodeLine{  next()}
\DoxyCodeLine{\}) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_serve_index_node_modules_http_errors_README_autotoc_md26846}{}\doxysection{API}\label{md_sfcode_node_modules_serve_index_node_modules_http_errors_README_autotoc_md26846}
This is the current API, currently extracted from Koa and subject to change.

All errors inherit from Java\+Script {\ttfamily Error} and the exported {\ttfamily create\+Error.\+Http\+Error}.\hypertarget{md_sfcode_node_modules_serve_index_node_modules_http_errors_README_autotoc_md26847}{}\doxysubsection{Error Properties}\label{md_sfcode_node_modules_serve_index_node_modules_http_errors_README_autotoc_md26847}

\begin{DoxyItemize}
\item {\ttfamily expose} -\/ can be used to signal if {\ttfamily message} should be sent to the client, defaulting to {\ttfamily false} when {\ttfamily status} $>$= 500
\item {\ttfamily headers} -\/ can be an object of header names to values to be sent to the client, defaulting to {\ttfamily undefined}. When defined, the key names should all be lower-\/cased
\item {\ttfamily message} -\/ the traditional error message, which should be kept short and all single line
\item {\ttfamily status} -\/ the status code of the error, mirroring {\ttfamily status\+Code} for general compatibility
\item {\ttfamily status\+Code} -\/ the status code of the error, defaulting to {\ttfamily 500}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_serve_index_node_modules_http_errors_README_autotoc_md26848}{}\doxysubsection{create\+Error(\mbox{[}status\mbox{]}, \mbox{[}message\mbox{]}, \mbox{[}properties\mbox{]})}\label{md_sfcode_node_modules_serve_index_node_modules_http_errors_README_autotoc_md26848}

\begin{DoxyCode}{0}
\DoxyCodeLine{var err = createError(404, 'This video does not exist!') }

\end{DoxyCode}



\begin{DoxyItemize}
\item {\ttfamily status\+: 500} -\/ the status code as a number
\item {\ttfamily message} -\/ the message of the error, defaulting to node\textquotesingle{}s text for that status code.
\item {\ttfamily properties} -\/ custom properties to attach to the object
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_serve_index_node_modules_http_errors_README_autotoc_md26849}{}\doxysubsection{new create\+Error\mbox{[}code $\vert$$\vert$ name\mbox{]}(\mbox{[}msg\mbox{]}))}\label{md_sfcode_node_modules_serve_index_node_modules_http_errors_README_autotoc_md26849}

\begin{DoxyCode}{0}
\DoxyCodeLine{var err = new createError.NotFound() }

\end{DoxyCode}



\begin{DoxyItemize}
\item {\ttfamily code} -\/ the status code as a number
\item {\ttfamily name} -\/ the name of the error as a \char`\"{}bumpy case\char`\"{}, i.\+e. {\ttfamily Not\+Found} or {\ttfamily Internal\+Server\+Error}.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_serve_index_node_modules_http_errors_README_autotoc_md26850}{}\doxysubsubsection{List of all constructors}\label{md_sfcode_node_modules_serve_index_node_modules_http_errors_README_autotoc_md26850}
\tabulinesep=1mm
\begin{longtabu}spread 0pt [c]{*{2}{|X[-1]}|}
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Status Code   }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Constructor Name    }\\\cline{1-2}
\endfirsthead
\hline
\endfoot
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Status Code   }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ Constructor Name    }\\\cline{1-2}
\endhead
400   &Bad\+Request    \\\cline{1-2}
401   &Unauthorized    \\\cline{1-2}
402   &Payment\+Required    \\\cline{1-2}
403   &Forbidden    \\\cline{1-2}
404   &Not\+Found    \\\cline{1-2}
405   &Method\+Not\+Allowed    \\\cline{1-2}
406   &Not\+Acceptable    \\\cline{1-2}
407   &Proxy\+Authentication\+Required    \\\cline{1-2}
408   &Request\+Timeout    \\\cline{1-2}
409   &Conflict    \\\cline{1-2}
410   &Gone    \\\cline{1-2}
411   &Length\+Required    \\\cline{1-2}
412   &Precondition\+Failed    \\\cline{1-2}
413   &Payload\+Too\+Large    \\\cline{1-2}
414   &URIToo\+Long    \\\cline{1-2}
415   &Unsupported\+Media\+Type    \\\cline{1-2}
416   &Range\+Not\+Satisfiable    \\\cline{1-2}
417   &Expectation\+Failed    \\\cline{1-2}
418   &Im\+ATeapot    \\\cline{1-2}
421   &Misdirected\+Request    \\\cline{1-2}
422   &Unprocessable\+Entity    \\\cline{1-2}
423   &Locked    \\\cline{1-2}
424   &Failed\+Dependency    \\\cline{1-2}
425   &Unordered\+Collection    \\\cline{1-2}
426   &Upgrade\+Required    \\\cline{1-2}
428   &Precondition\+Required    \\\cline{1-2}
429   &Too\+Many\+Requests    \\\cline{1-2}
431   &Request\+Header\+Fields\+Too\+Large    \\\cline{1-2}
451   &Unavailable\+For\+Legal\+Reasons    \\\cline{1-2}
500   &Internal\+Server\+Error    \\\cline{1-2}
501   &Not\+Implemented    \\\cline{1-2}
502   &Bad\+Gateway    \\\cline{1-2}
503   &Service\+Unavailable    \\\cline{1-2}
504   &Gateway\+Timeout    \\\cline{1-2}
505   &HTTPVersion\+Not\+Supported    \\\cline{1-2}
506   &Variant\+Also\+Negotiates    \\\cline{1-2}
507   &Insufficient\+Storage    \\\cline{1-2}
508   &Loop\+Detected    \\\cline{1-2}
509   &Bandwidth\+Limit\+Exceeded    \\\cline{1-2}
510   &Not\+Extended    \\\cline{1-2}
511   &Network\+Authentication\+Required   \\\cline{1-2}
\end{longtabu}
\hypertarget{md_sfcode_node_modules_serve_index_node_modules_http_errors_README_autotoc_md26851}{}\doxysection{License}\label{md_sfcode_node_modules_serve_index_node_modules_http_errors_README_autotoc_md26851}
\mbox{[}MIT\mbox{]}(LICENSE) 