This repository has been archived by the owner on Oct 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
errors.js.html
322 lines (318 loc) · 15.4 KB
/
errors.js.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" charset="utf-8">
<title>Waigo.js</title><!--[if IE]><link rel="shortcut icon" href="img/logo_32x32.ico" /><![endif]-->
<link rel="shortcut icon" href="/img/logo_114x114.png">
<meta name="msapplication-TileColor" content="#fff">
<meta name="msapplication-TileImage" content="/img/logo_144x144.png">
<link rel="stylesheet" media="screen" href="/style.css">
</head>
<body>
<header id="top" role="banner" class="navbar navbar-static-top">
<div class="container">
<div class="navbar-header">
<button type="button" data-toggle="collapse" data-target=".topmenu-navbar-collapse" class="navbar-toggle"><span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button><a href="/" class="navbar-brand">Waigo</a>
</div>
<div role="navigation" class="collapse navbar-collapse topmenu-navbar-collapse">
<ul class="nav navbar-nav">
<li><a id="guideNavItem" href="/">Guide</a></li>
<li><a href="/api">API</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="https://github.com/waigo/waigo">Github</a></li>
</ul>
</div>
</div>
</header>
<main id="content">
<div id="api">
<div class="container">
<div class="row">
<div role="complementary" class="col-md-3 waigo-api-index">
<ul class="nav hidden-sm hidden-xs">
<li><a href="../index.html">Main</a></li>
<li><a href="../config/base.js.html">config/base.js</a></li>
<li><a href="../config/development.js.html">config/development.js</a></li>
<li><a href="../config/index.js.html">config/index.js</a></li>
<li><a href="../controllers/main.js.html">controllers/main.js</a></li>
<li><a href="../routes.js.html">routes.js</a></li>
<li><a href="../server.js.html">server.js</a></li>
<li><a href="../support/db/mongoose.js.html">support/db/mongoose.js</a></li>
<li class="active"><a href="../support/errors.js.html">support/errors.js</a></li>
<li><a href="../support/logging/winston.js.html">support/logging/winston.js</a></li>
<li><a href="../support/middleware/errorHandler.js.html">support/middleware/errorHandler.js</a></li>
<li><a href="../support/middleware/outputFormats.js.html">support/middleware/outputFormats.js</a></li>
<li><a href="../support/middleware/responseTime.js.html">support/middleware/responseTime.js</a></li>
<li><a href="../support/middleware/sessions.js.html">support/middleware/sessions.js</a></li>
<li><a href="../support/outputFormats/html.js.html">support/outputFormats/html.js</a></li>
<li><a href="../support/outputFormats/json.js.html">support/outputFormats/json.js</a></li>
<li><a href="../support/routeMapper.js.html">support/routeMapper.js</a></li>
<li><a href="../support/session/store/mongo.js.html">support/session/store/mongo.js</a></li>
</ul>
<div class="visible-sm visible-xs">
<button type="button" data-toggle="collapse" data-target="#api-index-xs" class="btn btn-info">Show/hide API index</button>
<div id="api-index-xs" class="collapse">
<ul class="nav">
<li><a href="../index.html">Main</a></li>
<li><a href="../config/base.js.html">config/base.js</a></li>
<li><a href="../config/development.js.html">config/development.js</a></li>
<li><a href="../config/index.js.html">config/index.js</a></li>
<li><a href="../controllers/main.js.html">controllers/main.js</a></li>
<li><a href="../routes.js.html">routes.js</a></li>
<li><a href="../server.js.html">server.js</a></li>
<li><a href="../support/db/mongoose.js.html">support/db/mongoose.js</a></li>
<li class="active"><a href="../support/errors.js.html">support/errors.js</a></li>
<li><a href="../support/logging/winston.js.html">support/logging/winston.js</a></li>
<li><a href="../support/middleware/errorHandler.js.html">support/middleware/errorHandler.js</a></li>
<li><a href="../support/middleware/outputFormats.js.html">support/middleware/outputFormats.js</a></li>
<li><a href="../support/middleware/responseTime.js.html">support/middleware/responseTime.js</a></li>
<li><a href="../support/middleware/sessions.js.html">support/middleware/sessions.js</a></li>
<li><a href="../support/outputFormats/html.js.html">support/outputFormats/html.js</a></li>
<li><a href="../support/outputFormats/json.js.html">support/outputFormats/json.js</a></li>
<li><a href="../support/routeMapper.js.html">support/routeMapper.js</a></li>
<li><a href="../support/session/store/mongo.js.html">support/session/store/mongo.js</a></li>
</ul>
</div>
</div>
</div>
<div role="main" class="col-md-7 waigo-api-content">
<section id="_">
<h1>_</h1>
<div class="description"><p>Exceptions and error handlers.</p> </div>
<h5 class="subheader"></h5>
<p>
<div class="label label-success radius ctx-type">declaration</div>
</p>
</section>
<pre><code class="language-javascript">var _ = require('lodash'),
Promise = require('bluebird'),
util = require('util');</code></pre>
<section id="errorToViewObject">
<h1>errorToViewObject</h1>
<div class="description"><p>Convert given error to view object.</p> </div>
<h5 class="subheader"></h5>
<p>
<div class="label label-success radius ctx-type">declaration</div><span class="symbolReturns">-> Promise</span>
</p>
</section>
<table class="params table table-bordered table-striped">
<thead>
<tr>
<th style="width:20%">Option</th>
<th style="width:20%">Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name">{Error}</td>
<td class="type">error</td>
<td class="description">error object. </td>
</tr>
</tbody>
</table>
<pre><code class="language-javascript">var errorToViewObject = exports.toViewObject = function(error) {
if (_.isFunction(error.toViewObject)) {
return Promise.resolve(error.toViewObject());
} else {
return Promise.resolve({
msg: error.message
});
}
};</code></pre>
<section id="BaseError">
<h1>BaseError</h1>
<div class="description"><p>Base error class.</p> </div>
<h5 class="subheader"></h5>
<p>
<div class="label label-success radius ctx-type">declaration</div>
</p>
</section>
<table class="params table table-bordered table-striped">
<thead>
<tr>
<th style="width:20%">Option</th>
<th style="width:20%">Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name">{String}</td>
<td class="type">msg</td>
<td class="description">error message.</td>
</tr>
<tr>
<td class="name">{Number}</td>
<td class="type">status</td>
<td class="description">HTTP return status code to set.</td>
</tr>
</tbody>
</table>
<pre><code class="language-javascript">var BaseError = exports.BaseError = function(msg, status) {
Error.call(this, this.message);
this.name = 'BaseError';
this.message = msg || 'An error occurred';
this.status = status || 500;
Error.captureStackTrace(this, BaseError);
};
util.inherits(BaseError, Error);</code></pre>
<section id="toViewObject">
<h1>toViewObject</h1>
<div class="description"><p>Get renderable representation of this error.</p> </div>
<h5 class="subheader"></h5>
<p>
<div class="label label-info radius ctx-type">method</div><span class="symbolReturns">-> Promise</span>
</p>
</section>
<pre><code class="language-javascript">BaseError.prototype.toViewObject = function() {
return Promise.resolve({
type: this.name,
msg: this.message
});
};</code></pre>
<section id="createSubType">
<h1>createSubType</h1>
<div class="description"><p>Create a subclass of this error type.</p> </div>
<h5 class="subheader"></h5>
<p>
<div class="label label-info radius ctx-type">method</div><span class="symbolReturns">-> Function</span>
</p>
</section>
<table class="params table table-bordered table-striped">
<thead>
<tr>
<th style="width:20%">Option</th>
<th style="width:20%">Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name">{String}</td>
<td class="type">subTypeErrorName</td>
<td class="description">name of this new error type.</td>
</tr>
<tr>
<td class="name">{Object}</td>
<td class="type">options</td>
<td class="description">additional options.</td>
</tr>
<tr>
<td class="name">{Object}</td>
<td class="type">options.message</td>
<td class="description">default error message.</td>
</tr>
<tr>
<td class="name">{Object}</td>
<td class="type">options.status</td>
<td class="description">default error status. </td>
</tr>
</tbody>
</table>
<pre><code class="language-javascript">BaseError.createSubType = function(subTypeErrorName, options) {
options = options || {};
var newErrorClass = function(msg, status) {
BaseError.call(this, msg || options.message, status || options.status);
this.name = subTypeErrorName;
Error.captureStackTrace(this, newErrorClass);
};
util.inherits(newErrorClass, BaseError);
return newErrorClass;
};</code></pre>
<section id="MultipleError">
<h1>MultipleError</h1>
<div class="description"><p>Multiple errors grouped together.</p> </div>
<h5 class="subheader"></h5>
<p>
<div class="label label-success radius ctx-type">declaration</div>
</p>
</section>
<table class="params table table-bordered table-striped">
<thead>
<tr>
<th style="width:20%">Option</th>
<th style="width:20%">Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name">{Object}</td>
<td class="type">errors</td>
<td class="description">key-value map of errors, where each value is itself an `Error` instance.</td>
</tr>
<tr>
<td class="name">{Number}</td>
<td class="type">status</td>
<td class="description">HTTP return status code to set.</td>
</tr>
</tbody>
</table>
<pre><code class="language-javascript">var MultipleError = exports.MultipleError = function(errors, status) {
BaseError.call(this, 'There were multiple errors', status);
this.name = 'MultipleError';
this.errors = errors || {};
Error.captureStackTrace(this, MultipleError);
};
util.inherits(MultipleError, BaseError);</code></pre>
<section id="toViewObject">
<h1>toViewObject</h1>
<div class="description"><p>@see BaseError#toViewObject</p> </div>
<h5 class="subheader"></h5>
<p>
<div class="label label-info radius ctx-type">method</div>
</p>
</section>
<pre><code class="language-javascript">MultipleError.prototype.toViewObject = function() {
var self = this;
return Promise.props(
_.mapValues(self.errors, function(err) {
return errorToViewObject(err);
})
)
.then(function gotViewObjects(viewObjects) {
return {
type: self.name,
errors: viewObjects
};
});
};</code></pre>
</div>
<div class="col-md-2">
<div role="complementary" class="waigo-content-menu hidden-print">
<ul class="nav">
<li><a href="#_"><span>_</span></a></li>
<li><a href="#errorToViewObject"><span>errorToViewObject</span></a></li>
<li><a href="#BaseError"><span>BaseError</span></a></li>
<li><a href="#toViewObject"><span>toViewObject()</span></a></li>
<li><a href="#createSubType"><span>createSubType()</span></a></li>
<li><a href="#MultipleError"><span>MultipleError</span></a></li>
<li><a href="#toViewObject"><span>toViewObject()</span></a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
</main>
<footer role="contentinfo"><p>Built by <a href="http://hiddentao.com">hiddentao</a></p>
<p>This page was <a href="https://github.com/waigo/waigojs.com-generator">generated</a> on Mon, 24 Feb 2014 16:51:37 GMT</p>
</footer>
<script type="text/javascript" src="/scripts.js"></script>
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(["setDomains", ["*.waigojs.com","*.waigo.github.io"]]);
_paq.push(["trackPageView"]);
_paq.push(["enableLinkTracking"]);
(function() {
var u=(("https:" == document.location.protocol) ? "https" : "http") + "://piwik.hiddentao.com/";
_paq.push(["setTrackerUrl", u+"piwik.php"]);
_paq.push(["setSiteId", "3"]);
var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0]; g.type="text/javascript";
g.defer=true; g.async=true; g.src=u+"piwik.js"; s.parentNode.insertBefore(g,s);
})();
</script>
</body>
</html>