Skip to content

Commit 721eada

Browse files
author
Christoph Werner
committed
Changed rollback errors to RollbackError
Also adjusted instanceof test
1 parent f5b2329 commit 721eada

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

lib/index.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Object.defineProperty(exports, "__esModule", {
44
value: true
55
});
6-
exports.PatchError = undefined;
6+
exports.RollbackError = undefined;
77

88
exports.default = function (schema, opts) {
99
var options = (0, _lodash.merge)({}, defaultOptions, opts);
@@ -38,7 +38,7 @@ exports.default = function (schema, opts) {
3838
return new _bluebird2.default(function (resolve, reject) {
3939
// patch doesn't exist
4040
if (! ~(0, _lodash.map)(patches, 'id').indexOf(patchId)) {
41-
return reject(new PatchError('patch doesn\'t exist'));
41+
return reject(new RollbackError('patch doesn\'t exist'));
4242
}
4343

4444
// get all patches that should be applied
@@ -49,7 +49,7 @@ exports.default = function (schema, opts) {
4949
// if the patches that are going to be applied are all existing patches,
5050
// the rollback attempts to rollback to the latest patch
5151
if (patches.length === apply.length) {
52-
return reject(new PatchError('rollback to latest patch'));
52+
return reject(new RollbackError('rollback to latest patch'));
5353
}
5454

5555
// apply patches to `state`
@@ -173,21 +173,21 @@ function _extendableBuiltin(cls) {
173173
return ExtendableBuiltin;
174174
}
175175

176-
var PatchError = exports.PatchError = function (_extendableBuiltin2) {
177-
_inherits(PatchError, _extendableBuiltin2);
176+
var RollbackError = exports.RollbackError = function (_extendableBuiltin2) {
177+
_inherits(RollbackError, _extendableBuiltin2);
178178

179-
function PatchError(message) {
180-
_classCallCheck(this, PatchError);
179+
function RollbackError(message) {
180+
_classCallCheck(this, RollbackError);
181181

182-
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(PatchError).call(this));
182+
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(RollbackError).call(this));
183183

184184
Error.captureStackTrace(_this, _this.constructor);
185185
_this.name = _this.constructor.name;
186186
_this.message = message;
187187
return _this;
188188
}
189189

190-
return PatchError;
190+
return RollbackError;
191191
}(_extendableBuiltin(Error));
192192

193193
var createPatchModel = function createPatchModel(options) {

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import jsonpatch from 'fast-json-patch'
55
import { decamelize, pascalize } from 'humps'
66
import { dropRightWhile, each, map, merge, omit } from 'lodash'
77

8-
export class PatchError extends Error {
8+
export class RollbackError extends Error {
99
constructor (message) {
1010
super()
1111
Error.captureStackTrace(this, this.constructor)
@@ -71,7 +71,7 @@ export default function (schema, opts) {
7171
.then((patches) => new Promise((resolve, reject) => {
7272
// patch doesn't exist
7373
if (!~map(patches, 'id').indexOf(patchId)) {
74-
return reject(new PatchError('patch doesn\'t exist'))
74+
return reject(new RollbackError('patch doesn\'t exist'))
7575
}
7676

7777
// get all patches that should be applied
@@ -80,7 +80,7 @@ export default function (schema, opts) {
8080
// if the patches that are going to be applied are all existing patches,
8181
// the rollback attempts to rollback to the latest patch
8282
if (patches.length === apply.length) {
83-
return reject(new PatchError('rollback to latest patch'))
83+
return reject(new RollbackError('rollback to latest patch'))
8484
}
8585

8686
// apply patches to `state`

test/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import assert from 'assert'
22
import { map } from 'lodash'
33
import Promise, { join } from 'bluebird'
44
import mongoose, { Schema } from 'mongoose'
5-
import patchHistory from '../src'
5+
import patchHistory, { RollbackError } from '../src'
66

77
const ObjectId = mongoose.Types.ObjectId
88

@@ -159,7 +159,7 @@ describe('mongoose-patch-history', () => {
159159
.then((post) => {
160160
return post.rollback(ObjectId())
161161
.then(() => { assert(false); done() })
162-
.catch((err) => { assert(err instanceof Error); done() })
162+
.catch((err) => { assert(err instanceof RollbackError); done() })
163163
})
164164
})
165165

@@ -169,7 +169,7 @@ describe('mongoose-patch-history', () => {
169169
.then(([post, latestPatch]) => {
170170
return post.rollback(latestPatch.id)
171171
.then(() => { assert(false); done() })
172-
.catch((err) => { assert(err instanceof Error); done() })
172+
.catch((err) => { assert(err instanceof RollbackError); done() })
173173
})
174174
})
175175

0 commit comments

Comments
 (0)