Skip to content

Commit d78beb8

Browse files
authored
Merge branch 'master' into create-generate-id
2 parents fefe957 + 2c23d85 commit d78beb8

File tree

12 files changed

+5546
-1696
lines changed

12 files changed

+5546
-1696
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
*.tgz
2-
complexity
3-
coverage.html
42
jsonapi-server.cpuprofile
53
node_modules
64
npm-debug.log
5+
/.nyc_output/
6+
/coverage/

.travis.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ dist: trusty
22
sudo: false
33
language: node_js
44
node_js:
5-
- 4
65
- 6
76
- 8
7+
before_install:
8+
- npm install -g npm@latest
9+
- npm install -g greenkeeper-lockfile@latest
10+
before_script: greenkeeper-lockfile-update
811
script: npm run ci
12+
after_script: greenkeeper-lockfile-upload
13+
after_success: npm run coverage
914
notifications:
1015
email: false

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
- 2017-11-03 - v4.0.0
2+
- 2017-11-03 - Return error when a response item does not validate.
3+
- 2017-11-03 - Remove Node.js 4 support.
4+
- 2017-10-21 - v3.2.2
5+
- 2017-10-21 - Report coverage with Coveralls.
6+
- 2017-10-21 - Modernise script.
17
- 2017-09-23 - v3.2.1
28
- 2017-09-23 - Fix packaging.
39
- 2017-09-19 - v3.2.0

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
[![Build Status](https://travis-ci.org/holidayextras/jsonapi-server.svg?branch=master)](https://travis-ci.org/holidayextras/jsonapi-server)
2+
[![Coverage Status](https://coveralls.io/repos/github/holidayextras/jsonapi-server/badge.svg?branch=master)](https://coveralls.io/github/holidayextras/jsonapi-server?branch=master)
23
[![npm version](https://badge.fury.io/js/jsonapi-server.svg)](http://badge.fury.io/js/jsonapi-server)
34
[![Dependencies Status](https://david-dm.org/holidayextras/jsonapi-server.svg)](https://david-dm.org/holidayextras/jsonapi-server)
45

56
# jsonapi-server
67

8+
[![Greenkeeper badge](https://badges.greenkeeper.io/holidayextras/jsonapi-server.svg)](https://greenkeeper.io/)
9+
710
A config driven NodeJS framework implementing [`json:api`](http://jsonapi.org/) and [`GraphQL`](http://graphql.org/). You define the resources, it provides the api.
811

912
### Motivation / Justification / Rationale
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict'
2+
3+
const jsonApi = require('../..')
4+
5+
module.exports = new jsonApi.MemoryHandler()

example/resources/brokenResponse.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict'
2+
3+
const jsonApi = require('../../.')
4+
const brokenResponseHandler = require('../handlers/brokenResponseHandler.js')
5+
6+
jsonApi.define({
7+
namespace: 'json:api',
8+
resource: 'brokenResponse',
9+
description: 'Example demonstrating error handling of broken responses',
10+
handlers: brokenResponseHandler,
11+
searchParams: { },
12+
attributes: {
13+
boolean: jsonApi.Joi.boolean(),
14+
number: jsonApi.Joi.number()
15+
},
16+
examples: [
17+
{
18+
id: 'b3ea78f4-8d03-4708-9945-d58cadc97b04',
19+
type: 'brokenResponse',
20+
boolean: 1,
21+
number: '3'
22+
}
23+
]
24+
})

lib/responseHelper.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,16 @@ responseHelper._enforceSchemaOnObject = (item, schema, callback) => {
3434
Joi.validate(item, schema, (err, sanitisedItem) => {
3535
if (err) {
3636
debug.validationError(err.message, JSON.stringify(item))
37-
return callback(null, null)
37+
const res = {
38+
status: '500',
39+
code: 'EINVALIDITEM',
40+
title: 'Item in response does not validate',
41+
detail: {
42+
item: item,
43+
error: err.message
44+
}
45+
}
46+
return callback(res)
3847
}
3948

4049
const dataItem = responseHelper._generateDataItem(sanitisedItem, schema)

0 commit comments

Comments
 (0)