Tim Alby 7 лет назад
Родитель
Сommit
9afd8e4e5d
2 измененных файлов с 19 добавлено и 18 удалено
  1. 10 10
      libraries/o-error/README.md
  2. 9 8
      libraries/o-error/index.js

+ 10 - 10
libraries/o-error/README.md

@@ -8,17 +8,17 @@ Make custom error types that:
 
 ## For ES6
 
-ES6 classes make it easy to define custom errors by subclassing `Error`. Subclassing `OErrors.OError` adds a few extra helpers.
+ES6 classes make it easy to define custom errors by subclassing `Error`. Subclassing `OError` adds a few extra helpers.
 
 ### Usage
 
 #### Throw an error directly
 
 ```js
-const OErrors = require('overleaf-error-type')
+const OError = require('overleaf-error-type')
 
 function doSomethingBad () {
-  throw new OErrors.OError({
+  throw new OError({
     message: 'did something bad',
     info: { thing: 'foo' }
   })
@@ -34,7 +34,7 @@ doSomethingBad()
 #### Custom error class
 
 ```js
-class FooError extends OErrors.OError {
+class FooError extends OError {
   constructor (options) {
     super({ message: 'failed to foo', ...options })
   }
@@ -77,7 +77,7 @@ doFoo2()
 try {
   doFoo2()
 } catch (err) {
-  console.log(OErrors.getFullStack(err))
+  console.log(OError.getFullStack(err))
 }
 // =>
 // FooError: failed to foo: bad
@@ -101,9 +101,9 @@ The approach is based mainly on https://gist.github.com/justmoon/15511f92e5216fa
 #### Define a standalone error class
 
 ```js
-const errorType = require('overleaf-error-type')
+const OError = require('overleaf-error-type')
 
-const CustomError = errorType.define('CustomError')
+const CustomError = OError.define('CustomError')
 
 function doSomethingBad () {
   throw new CustomError()
@@ -117,7 +117,7 @@ doSomethingBad()
 #### Define an error subclass
 
 ```js
-const SubCustomError = errorType.extend(CustomError, 'SubCustomError')
+const SubCustomError = OError.extend(CustomError, 'SubCustomError')
 
 try {
   throw new SubCustomError()
@@ -132,7 +132,7 @@ try {
 #### Add custom message and/or properties
 
 ```js
-const UserNotFoundError = errorType.define('UserNotFoundError',
+const UserNotFoundError = OError.define('UserNotFoundError',
   function (userId) {
     this.message = `User not found: ${userId}`
     this.userId = userId
@@ -151,7 +151,7 @@ class User {
   }
 }
 
-errorType.defineIn(User, 'UserNotFoundError', function (userId) {
+OError.defineIn(User, 'UserNotFoundError', function (userId) {
   this.message = `User not found: ${userId}`
   this.userId = userId
 })

+ 9 - 8
libraries/o-error/index.js

@@ -92,10 +92,9 @@ function hasCauseInstanceOf (error, klass) {
   return error instanceof klass || hasCauseInstanceOf(error.cause, klass)
 }
 
-exports.OError = OError
-exports.getFullInfo = getFullInfo
-exports.getFullStack = getFullStack
-exports.hasCauseInstanceOf = hasCauseInstanceOf
+OError.getFullInfo = getFullInfo
+OError.getFullStack = getFullStack
+OError.hasCauseInstanceOf = hasCauseInstanceOf
 
 //
 // For ES5
@@ -133,7 +132,9 @@ function defineErrorTypeIn (container, name, builder) {
   extendErrorTypeIn(container, Error, name, builder)
 }
 
-exports.extend = extendErrorType
-exports.define = defineErrorType
-exports.extendIn = extendErrorTypeIn
-exports.defineIn = defineErrorTypeIn
+OError.extend = extendErrorType
+OError.define = defineErrorType
+OError.extendIn = extendErrorTypeIn
+OError.defineIn = defineErrorTypeIn
+
+module.exports = OError