Skip to content
Myr

More error handling docs

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 6b54c1b · Browse files · 3 files+59 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+59 added−0 removed

  • other:+59 added−0 removed

3 files+59 added−0 removed

modified:docs/guide.1+29 added
345 unmodified lines
346.fi347.348.IP "" 0349.350.P351Our apps could also utilize the Connect \fIerrorHandler\fR middleware to report on exceptions\. For example if we wish to output exceptions in \"development\" mode to \fIstderr\fR we can use:352.353.IP "" 4354.355.nf356357app\.use(\'/\', connect\.errorHandler({ dumpExceptions: true }));358.359.fi360.361.IP "" 0362.363.P364Also during development we may want fancy html pages to show exceptions that are passed or thrown, so we can set \fIshowStack\fR to true:365.366.IP "" 4367.368.nf369370app\.use(\'/\', connect\.errorHandler({ showStack: true, dumpExceptions: true }));371.372.fi373.374.IP "" 0375.376.P377The \fIerrorHandler\fR middleware also responds with \fIjson\fR if \fIAccept: application/json\fR is present, which is useful for developing apps that rely heavily on client\-side JavaScript\.378.379.SS "View Rendering"380View filenames take the form \fINAME\fR\.\fIENGINE\fR, where \fIENGINE\fR is the name of the module that will be required\. For example the view \fIlayout\.ejs\fR will tell the view system to \fIrequire(\'ejs\')\fR, the module being loaded must (currently) export the method \fIexports\.render(str, options)\fR to comply with Express, however with will likely be extensible in the future\.381.382.P
478 unmodified lines
modified:docs/guide.html+16 added
441 unmodified lines
442 });443});444</code></pre>445446<p>Our apps could also utilize the Connect <em>errorHandler</em> middleware447to report on exceptions. For example if we wish to output exceptions448in "development" mode to <em>stderr</em> we can use:</p>449450<pre><code>app.use('/', connect.errorHandler({ dumpExceptions: true }));451</code></pre>452453<p>Also during development we may want fancy html pages to show exceptions454that are passed or thrown, so we can set <em>showStack</em> to true:</p>455456<pre><code>app.use('/', connect.errorHandler({ showStack: true, dumpExceptions: true }));457</code></pre>458459<p>The <em>errorHandler</em> middleware also responds with <em>json</em> if <em>Accept: application/json</em>460is present, which is useful for developing apps that rely heavily on client-side JavaScript.</p>461462<h3 id="View-Rendering">View Rendering</h3>463464<p>View filenames take the form <em>Express</em>.<em>ENGINE</em>, where <em>ENGINE</em> is the name465of the module that will be required. For example the view <em>layout.ejs</em> will
322 unmodified lines
modified:docs/guide.md+14 added
211 unmodified lines
212 } 213 });214 });215216Our apps could also utilize the Connect _errorHandler_ middleware217to report on exceptions. For example if we wish to output exceptions 218in "development" mode to _stderr_ we can use:219220 app.use('/', connect.errorHandler({ dumpExceptions: true }));221222Also during development we may want fancy html pages to show exceptions223that are passed or thrown, so we can set _showStack_ to true:224225 app.use('/', connect.errorHandler({ showStack: true, dumpExceptions: true }));226227The _errorHandler_ middleware also responds with _json_ if _Accept: application/json_228is present, which is useful for developing apps that rely heavily on client-side JavaScript.229230### View Rendering231232View filenames take the form _NAME_._ENGINE_, where _ENGINE_ is the name233of the module that will be required. For example the view _layout.ejs_ will
283 unmodified lines