\href{https://npmjs.org/package/http-errors}{\texttt{ }} \href{https://nodejs.org/en/download}{\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?branch=master}{\texttt{ }}

Create HTTP errors for Express, Koa, Connect, etc. with ease.\hypertarget{md_sfcode_node_modules_http_errors_README_autotoc_md11718}{}\doxysection{Install}\label{md_sfcode_node_modules_http_errors_README_autotoc_md11718}
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_http_errors_README_autotoc_md11719}{}\doxysection{Example}\label{md_sfcode_node_modules_http_errors_README_autotoc_md11719}

\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_http_errors_README_autotoc_md11720}{}\doxysection{API}\label{md_sfcode_node_modules_http_errors_README_autotoc_md11720}
This is the current API, currently extracted from Koa and subject to change.\hypertarget{md_sfcode_node_modules_http_errors_README_autotoc_md11721}{}\doxysubsection{Error Properties}\label{md_sfcode_node_modules_http_errors_README_autotoc_md11721}

\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_http_errors_README_autotoc_md11722}{}\doxysubsection{create\+Error(\mbox{[}status\mbox{]}, \mbox{[}message\mbox{]}, \mbox{[}properties\mbox{]})}\label{md_sfcode_node_modules_http_errors_README_autotoc_md11722}
Create a new error object with the given message {\ttfamily msg}. The error object inherits from {\ttfamily create\+Error.\+Http\+Error}.


\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_http_errors_README_autotoc_md11723}{}\doxysubsection{create\+Error(\mbox{[}status\mbox{]}, \mbox{[}error\mbox{]}, \mbox{[}properties\mbox{]})}\label{md_sfcode_node_modules_http_errors_README_autotoc_md11723}
Extend the given {\ttfamily error} object with {\ttfamily create\+Error.\+Http\+Error} properties. This will not alter the inheritance of the given {\ttfamily error} object, and the modified {\ttfamily error} object is the return value.


\begin{DoxyCode}{0}
\DoxyCodeLine{fs.readFile('foo.txt', function (err, buf) \{}
\DoxyCodeLine{  if (err) \{}
\DoxyCodeLine{    if (err.code === 'ENOENT') \{}
\DoxyCodeLine{      var httpError = createError(404, err, \{ expose: false \})}
\DoxyCodeLine{    \} else \{}
\DoxyCodeLine{      var httpError = createError(500, err)}
\DoxyCodeLine{    \}}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\}) }

\end{DoxyCode}



\begin{DoxyItemize}
\item {\ttfamily status} -\/ the status code as a number
\item {\ttfamily error} -\/ the error object to extend
\item {\ttfamily properties} -\/ custom properties to attach to the object
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_http_errors_README_autotoc_md11724}{}\doxysubsection{new create\+Error\mbox{[}code $\vert$$\vert$ name\mbox{]}(\mbox{[}msg\mbox{]}))}\label{md_sfcode_node_modules_http_errors_README_autotoc_md11724}
Create a new error object with the given message {\ttfamily msg}. The error object inherits from {\ttfamily create\+Error.\+Http\+Error}.


\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_http_errors_README_autotoc_md11725}{}\doxysubsubsection{List of all constructors}\label{md_sfcode_node_modules_http_errors_README_autotoc_md11725}
\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_http_errors_README_autotoc_md11726}{}\doxysection{License}\label{md_sfcode_node_modules_http_errors_README_autotoc_md11726}
\mbox{[}MIT\mbox{]}(LICENSE) 