Skip to content
Snippets Groups Projects
Commit 2969bf67 authored by Jure's avatar Jure
Browse files

feat: add @pubsweet/errors

Previously errors were nested in pubsweet-server. Since they get used all over the place, they're
not living in their own package called @pubsweet/errors.

BREAKING CHANGE: If you required errors deeply from pubsweet-server before, i.e.
`pubsweet-server/src/errors`, this will no longer work, and you need to change your require to
`@pubsweet/errors`.
parent a7a43b22
No related branches found
No related tags found
No related merge requests found
Showing
with 204 additions and 25 deletions
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
"knex": "^0.16.3", "knex": "^0.16.3",
"lodash": "^4.17.11", "lodash": "^4.17.11",
"objection": "^1.2.3", "objection": "^1.2.3",
"uuid": "^3.3.2" "uuid": "^3.3.2",
"@pubsweet/errors": "^1.0.0"
}, },
"devDependencies": { "devDependencies": {
"pubsweet-server": "^11.0.0" "pubsweet-server": "^11.0.0"
......
const uuid = require('uuid') const uuid = require('uuid')
const { Model, transaction } = require('objection') const { Model, transaction } = require('objection')
const logger = require('@pubsweet/logger') const logger = require('@pubsweet/logger')
const NotFoundError = require('./NotFoundError') const { NotFoundError } = require('@pubsweet/errors')
const db = require('@pubsweet/db-manager/src/db') const db = require('@pubsweet/db-manager/src/db')
const { merge } = require('lodash') const { merge } = require('lodash')
const config = require('config') const config = require('config')
......
...@@ -13,13 +13,13 @@ ...@@ -13,13 +13,13 @@
"@pubsweet/models": "^0.1.0", "@pubsweet/models": "^0.1.0",
"http-status-codes": "^1.3.0", "http-status-codes": "^1.3.0",
"passport": "^0.4.0", "passport": "^0.4.0",
"pubsweet-server": "^11.0.0",
"pubsweet-sse": "^1.0.3" "pubsweet-sse": "^1.0.3"
}, },
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
}, },
"peerDependencies": { "peerDependencies": {
"pubsweet-server": "^11.0.0",
"lodash": "^4.17.11" "lodash": "^4.17.11"
} }
} }
...@@ -14,8 +14,11 @@ ...@@ -14,8 +14,11 @@
"@pubsweet/models": "^0.1.0", "@pubsweet/models": "^0.1.0",
"http-status-codes": "^1.3.0", "http-status-codes": "^1.3.0",
"passport": "^0.4.0", "passport": "^0.4.0",
"pubsweet-server": "^11.0.0", "pubsweet-sse": "^1.0.3",
"pubsweet-sse": "^1.0.3" "@pubsweet/errors": "^1.0.0"
},
"peerDependencies": {
"pubsweet-server": "^11.0.0"
}, },
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
......
...@@ -23,7 +23,7 @@ const authBearerAndPublic = passport.authenticate(['bearer', 'anonymous'], { ...@@ -23,7 +23,7 @@ const authBearerAndPublic = passport.authenticate(['bearer', 'anonymous'], {
const FragmentsAPI = app => { const FragmentsAPI = app => {
const authsome = require('pubsweet-server/src/helpers/authsome') const authsome = require('pubsweet-server/src/helpers/authsome')
const { AuthorizationError } = require('pubsweet-server/src/errors') const { AuthorizationError } = require('@pubsweet/errors')
const { Team, User, Fragment, Collection } = require('@pubsweet/models') const { Team, User, Fragment, Collection } = require('@pubsweet/models')
......
...@@ -17,7 +17,8 @@ ...@@ -17,7 +17,8 @@
"passport": "^0.4.0", "passport": "^0.4.0",
"passport-anonymous": "^1.0.1", "passport-anonymous": "^1.0.1",
"passport-http-bearer": "^1.0.1", "passport-http-bearer": "^1.0.1",
"passport-local": "^1.0.0" "passport-local": "^1.0.0",
"@pubsweet/errors": "^1.0.0"
}, },
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
......
...@@ -11,7 +11,7 @@ const authentication = require('./authentication') ...@@ -11,7 +11,7 @@ const authentication = require('./authentication')
const UsersAPI = app => { const UsersAPI = app => {
const User = require('./user') const User = require('./user')
const { ValidationError } = require('pubsweet-server/src/errors') const { ValidationError } = require('@pubsweet/errors')
const { const {
util: { util: {
......
...@@ -82,7 +82,7 @@ class User extends BaseModel { ...@@ -82,7 +82,7 @@ class User extends BaseModel {
} }
static async isUniq(user) { static async isUniq(user) {
const { ConflictError } = require('pubsweet-server/src/errors') const { ConflictError } = require('@pubsweet/errors')
let result let result
......
...@@ -10,7 +10,8 @@ ...@@ -10,7 +10,8 @@
"@pubsweet/db-manager": "^2.2.0", "@pubsweet/db-manager": "^2.2.0",
"lodash": "^4.17.11", "lodash": "^4.17.11",
"moment": "^2.18.1", "moment": "^2.18.1",
"passport": "^0.4.0" "passport": "^0.4.0",
"@pubsweet/errors": "^1.0.0"
}, },
"devDependencies": { "devDependencies": {
"body-parser": "^1.17.2", "body-parser": "^1.17.2",
......
...@@ -7,7 +7,7 @@ const { ...@@ -7,7 +7,7 @@ const {
models: { User, Fragment, Team, Collection }, models: { User, Fragment, Team, Collection },
} = require('@pubsweet/db-manager') } = require('@pubsweet/db-manager')
const authsome = require('pubsweet-server/src/helpers/authsome') const authsome = require('pubsweet-server/src/helpers/authsome')
const AuthorizationError = require('pubsweet-server/src/errors/AuthorizationError') const { AuthorizationError } = require('@pubsweet/errors')
const authBearer = passport.authenticate('bearer', { session: false }) const authBearer = passport.authenticate('bearer', { session: false })
......
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [1.2.0](https://gitlab.coko.foundation/pubsweet/pubsweet/compare/@pubsweet/base-model@1.1.0...@pubsweet/base-model@1.2.0) (2019-01-09)
### Bug Fixes
* fix BaseModel's updateProperties and findByField ([418a27a](https://gitlab.coko.foundation/pubsweet/pubsweet/commit/418a27a))
* improve BaseModel's handling of schema and updateProperties ([80f7f3f](https://gitlab.coko.foundation/pubsweet/pubsweet/commit/80f7f3f))
* **base-model:** improve BaseModel's save() ([bf8a438](https://gitlab.coko.foundation/pubsweet/pubsweet/commit/bf8a438))
* various migration related fixes ([2aef24a](https://gitlab.coko.foundation/pubsweet/pubsweet/commit/2aef24a))
* **base-model:** updated is always present ([c9e645d](https://gitlab.coko.foundation/pubsweet/pubsweet/commit/c9e645d))
### Features
* **base-model:** remove proxy for setting model properties ([e9ad1fa](https://gitlab.coko.foundation/pubsweet/pubsweet/commit/e9ad1fa))
* introduce [@pubsweet](https://gitlab.coko.foundation/pubsweet)/models package ([7c1a364](https://gitlab.coko.foundation/pubsweet/pubsweet/commit/7c1a364))
# [1.1.0](https://gitlab.coko.foundation/pubsweet/pubsweet/compare/@pubsweet/base-model@1.0.12...@pubsweet/base-model@1.1.0) (2018-12-12)
### Bug Fixes
* **base-model:** ensure updated is set on insert ([d04688b](https://gitlab.coko.foundation/pubsweet/pubsweet/commit/d04688b))
* **base-model:** make funcs private and rename vars ([3e64aa6](https://gitlab.coko.foundation/pubsweet/pubsweet/commit/3e64aa6))
* **base-model:** use trx within transaction ([8330615](https://gitlab.coko.foundation/pubsweet/pubsweet/commit/8330615))
### Features
* **base-model:** add test to check exception when saving stale data ([9d73525](https://gitlab.coko.foundation/pubsweet/pubsweet/commit/9d73525))
* **base-model:** protect save from stale data ([836a9b8](https://gitlab.coko.foundation/pubsweet/pubsweet/commit/836a9b8))
## [1.0.12](https://gitlab.coko.foundation/pubsweet/pubsweet/compare/@pubsweet/base-model@1.0.11...@pubsweet/base-model@1.0.12) (2018-12-04)
**Note:** Version bump only for package @pubsweet/base-model
## [1.0.11](https://gitlab.coko.foundation/pubsweet/pubsweet/compare/@pubsweet/base-model@1.0.10...@pubsweet/base-model@1.0.11) (2018-11-30)
**Note:** Version bump only for package @pubsweet/base-model
## [1.0.10](https://gitlab.coko.foundation/pubsweet/pubsweet/compare/@pubsweet/base-model@1.0.9...@pubsweet/base-model@1.0.10) (2018-11-29)
**Note:** Version bump only for package @pubsweet/base-model
<a name="1.0.9"></a>
## [1.0.9](https://gitlab.coko.foundation/pubsweet/pubsweet/compare/@pubsweet/base-model@1.0.8...@pubsweet/base-model@1.0.9) (2018-11-13)
**Note:** Version bump only for package @pubsweet/base-model
<a name="1.0.8"></a>
## [1.0.8](https://gitlab.coko.foundation/pubsweet/pubsweet/compare/@pubsweet/base-model@1.0.7...@pubsweet/base-model@1.0.8) (2018-11-05)
### Bug Fixes
* **base-model:** support graph inserts ([ff40287](https://gitlab.coko.foundation/pubsweet/pubsweet/commit/ff40287))
<a name="1.0.7"></a>
## [1.0.7](https://gitlab.coko.foundation/pubsweet/pubsweet/compare/@pubsweet/base-model@1.0.6...@pubsweet/base-model@1.0.7) (2018-10-17)
**Note:** Version bump only for package @pubsweet/base-model
<a name="1.0.6"></a>
## [1.0.6](https://gitlab.coko.foundation/pubsweet/pubsweet/compare/@pubsweet/base-model@1.0.5...@pubsweet/base-model@1.0.6) (2018-10-08)
**Note:** Version bump only for package @pubsweet/base-model
<a name="1.0.5"></a>
## [1.0.5](https://gitlab.coko.foundation/pubsweet/pubsweet/compare/@pubsweet/base-model@1.0.4...@pubsweet/base-model@1.0.5) (2018-09-29)
**Note:** Version bump only for package @pubsweet/base-model
<a name="1.0.4"></a>
## [1.0.4](https://gitlab.coko.foundation/pubsweet/pubsweet/compare/@pubsweet/base-model@1.0.3...@pubsweet/base-model@1.0.4) (2018-09-28)
**Note:** Version bump only for package @pubsweet/base-model
<a name="1.0.3"></a>
## [1.0.3](https://gitlab.coko.foundation/pubsweet/pubsweet/compare/@pubsweet/base-model@1.0.2...@pubsweet/base-model@1.0.3) (2018-09-27)
**Note:** Version bump only for package @pubsweet/base-model
<a name="1.0.2"></a>
## [1.0.2](https://gitlab.coko.foundation/pubsweet/pubsweet/compare/@pubsweet/base-model@1.0.1...@pubsweet/base-model@1.0.2) (2018-09-27)
**Note:** Version bump only for package @pubsweet/base-model
<a name="1.0.1"></a>
## [1.0.1](https://gitlab.coko.foundation/pubsweet/pubsweet/compare/@pubsweet/base-model@1.0.0...@pubsweet/base-model@1.0.1) (2018-09-25)
**Note:** Version bump only for package @pubsweet/base-model
<a name="1.0.0"></a>
# 1.0.0 (2018-09-20)
### Features
* add base-model package for standalone data models ([fc446e8](https://gitlab.coko.foundation/pubsweet/pubsweet/commit/fc446e8)), closes [#395](https://gitlab.coko.foundation/pubsweet/pubsweet/issues/395)
### BREAKING CHANGES
* In PubSweet server, the exported thing is no longer startServer directly, but it's
now part of the exported object. This will break applications that use the equivalent of const
startServer = require('pubsweet-server'). The new method for getting a startServer is const {
startServer } = require('pubsweet-server').
# Errors
Use like so:
```
import { NotFoundError } from '@pubsweet/errors'
throw new NotFoundError()
```
{
"name": "@pubsweet/errors",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Adam Hyde",
"license": "MIT",
"dependencies": {
"http-status-codes": "^1.3.0"
},
"publishConfig": {
"access": "public"
}
}
File moved
...@@ -52,7 +52,8 @@ ...@@ -52,7 +52,8 @@
"subscriptions-transport-ws": "^0.9.12", "subscriptions-transport-ws": "^0.9.12",
"uuid": "^3.0.1", "uuid": "^3.0.1",
"waait": "^1.0.2", "waait": "^1.0.2",
"winston": "^2.2.0" "winston": "^2.2.0",
"@pubsweet/errors": "^1.0.0"
}, },
"devDependencies": { "devDependencies": {
"eventsource": "^1.0.4", "eventsource": "^1.0.4",
......
const STATUS = require('http-status-codes')
class NotFoundError extends Error {
constructor(message, status) {
super(message)
Error.captureStackTrace(this, 'NotFoundError')
this.name = 'NotFoundError'
this.message = message || 'Not found'
this.status = status || STATUS.NOT_FOUND
}
}
module.exports = NotFoundError
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment