You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* release:
update version to 0.2.0
docs(README): update
docs(README): update chinese README
chore(CI): cache node_modules and apt in Travis-CI
chore(CI): test node v5.1 and v5 & if npm version > 3.3 upgrade it to latest before CI test
style(test): change codes for eslint
docs(README): update chinese README
chore: update jsduck and package.json
feat: refactoring Ero to be a class, no longer be singleton
docs(README): add TOC
chore(gulp-license): use my gulp-license
style(eslint): upgrade eslint for my style
docs(README): update copyright and license descriptions
`new Ero()` create an ero instance, which is a space storing error classes, and providing some utility functions.
139
+
140
+
ero contains these members as below:
141
+
142
+
-[template](#error-template)
143
+
-[BaseError](#baseerror)
144
+
-[Errors](#error-class): All customized errors are put here.
145
+
146
+
Each ero space are independent.
147
+
148
+
Ero provides some utility functions, such as `Ero.isCustomError`. Please refer to [API document][API - Ero].
149
+
150
+
<aname="error-template"></a>
151
+
### Error Template
109
152
110
153
The error template is used to constrain the properties of the error definition.
111
154
@@ -114,17 +157,36 @@ Furthermore, the template can also set default values for the properties of all
114
157
115
158
The `message` property of template do nothing besides force the developer to explain the meaning of each property of error definition.
116
159
117
-
## Error Definitions
160
+
<aname="error-definitions"></a>
161
+
### Error Definitions
118
162
119
163
Each error definition is used to create the corresponding error class.
120
164
121
-
Each error definition is defined by `<error name>: <properties definitions>`, which `<error name>` should be unique.
165
+
Each error definition is defined by a key/value pair `<error name>: <properties definitions>`, in which `<error name>` should be unique.
122
166
123
167
`Properties definitions` is an object composed of many key/value pairs.
124
168
It will be assigned to the prototype of corresponding error class, as the default value for each error instance.
125
169
126
-
## Error Class
127
-
Each error definitions provided will be used to generate corresponding error classes, which are inherited from the [`BaseError`](http://adoyle.me/Ero.js/#!/api/BaseError) base class.
170
+
<aname="baseerror"></a>
171
+
### BaseError
172
+
173
+
The Ero.js provides a `BaseError` class as the base class of all customized error classes.
174
+
175
+
`BaseError` class has properties as below:
176
+
177
+
- meta: {Object} The metadata for error.
178
+
- message: {String} The error message.
179
+
-[stack]: {String} The error stack. It is existed when `captureStackTrace` is `true`.
180
+
- captureStackTrace: {Boolean} Whether to capture the stack trace. Default to `true`.
181
+
- name: {String} The name of error class.
182
+
- ERROR_STACK_SEPARATOR: {String} The separator between multi error stacks.
183
+
- MESSAGE_CONNECTOR: {String} The connector between multi error messages.
184
+
185
+
Refer to [`API document - BaseError`][API - BaseError] for more details.
186
+
187
+
<aname="error-class"></a>
188
+
### Error Class
189
+
Each error definitions provided will be used to generate corresponding error classes, which are inherited from the [`BaseError`][BaseError] base class.
128
190
129
191
`BaseError` has a full featured constructor that is convenient for adding more useful information to error instance when you create it.
130
192
@@ -157,16 +219,40 @@ console.log(thirdErr.meta); // The secondMeta and thirdMeta will be added to er
157
219
console.log(thirdErr.stack); // These three error stacks will be together in a series.
158
220
```
159
221
160
-
Certainly, error, meta, message can be optional:
222
+
Certainly, error, meta, message are optional parameters:
### Creating error instance without capturing stack trace
233
+
234
+
`error.stack` is not required. It means that calling `var error = new Errors.SubError();` could not capture the error stack.
235
+
There is a scenario, developers need to create a error instance, while do not care about its error stack.
236
+
237
+
(It would not capture stack error, only when `SubError.captureStackTrace` is `false`. Refer to [BaseError][] for More informations)
238
+
239
+
<aname="multi-ero-instances"></a>
240
+
### Multi Ero Instances
241
+
242
+
In most cases, like building a web server application, you only need one ero instance for customizing your errors.
243
+
244
+
For framework libraries, you could create multi ero instances, for providing the error classes for framework layer and user layer.
245
+
246
+
For class libraries, I think it is unnecessary to use this project and the native error class is enough.
247
+
248
+
**Attentions**, the `template`, `BaseError` and `Errors` are independent between different ero instances. Thus `ero.isCustomError` could only recognize the errors which created based on the `Errors` in an ero.
249
+
250
+
<aname="api"></a>
166
251
## API
167
252
168
-
see http://adoyle.me/Ero.js/
253
+
The specifications of API, and details not mentioned in README, would be referenced at [API document][API].
169
254
255
+
<aname="versioning"></a>
170
256
## Versioning
171
257
172
258
The versioning follows the rules of SemVer 2.0.0.
@@ -175,19 +261,24 @@ The versioning follows the rules of SemVer 2.0.0.
175
261
176
262
For more information on SemVer, please visit http://semver.org/.
177
263
264
+
<aname="copyright-and-license"></a>
178
265
## Copyright and License
179
266
180
-
Copyright 2015-2016 ADoyle
267
+
Copyright (c) 2015-2016 ADoyle. The project is licensed under the **Apache License Version 2.0**.
268
+
269
+
See the [LICENSE][] file for the specific language governing permissions and limitations under the License.
181
270
182
-
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
183
-
You may obtain a copy of the License at
271
+
See the [NOTICE][] file distributed with this work for additional information regarding copyright ownership.
184
272
185
-
http://www.apache.org/licenses/LICENSE-2.0
186
273
187
-
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
188
-
See the License for the specific language governing permissions and limitations under the License.
274
+
<!-- Links -->
189
275
190
-
See the NOTICE file distributed with this work for additional information regarding copyright ownership.
0 commit comments