Skip to content

Commit

Permalink
fix error token
Browse files Browse the repository at this point in the history
  • Loading branch information
felixheck committed Nov 28, 2017
1 parent ce4fb40 commit 22a1587
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ assign('get', (data, colors, field) => (
))

assign('error', (data, colors, field = 'message') => {
if (!data.err && data.data.err) {
if (!get(data, 'err') && get(data, 'data.err')) {
data = data.data
}

if (!data.err.source) {
if (!get(data, 'err.source')) {
data.err.source = utils.getErrorSource(data.err)
}

Expand Down
4 changes: 3 additions & 1 deletion test/tokens.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ test('return requested general attributes', (t) => {

test('return requested alternative attributes', (t) => {
const mockData = {
data: 'foobar'
data: 'foobar',
err: 'foobar'
}

t.is(tokens['message'](mockData), mockData.data)
t.is(tokens['error'](mockData), undefined)
})

test('return requested req/res attributes', (t) => {
Expand Down

0 comments on commit 22a1587

Please sign in to comment.