Skip to content

Commit

Permalink
fix(typeformclient): echo api errors back to users (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
lirantal authored Jan 28, 2019
1 parent 32287fd commit 48a439f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions __tests__/Form/form.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,15 @@ describe('Form', () => {
forms: {
get: jest.fn(() => {
return {
code: 'FORM_NOT_FOUND'
code: 'FORM_NOT_FOUND',
description: 'form not found'
}
})
}
}

await expect(form._fetchForm(mockFormId)).rejects.toThrowError(
'Form not found, check the provided credentials'
'Typeform API returned an error: form not found'
)
})
})
Expand Down
4 changes: 2 additions & 2 deletions src/Form/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module.exports = class Form {
const form = {}
const formResult = await this.client.forms.get({uid: formId})

if (formResult.code && formResult.code === 'FORM_NOT_FOUND') {
throw new Error('Form not found, check the provided credentials')
if (formResult.code) {
throw new Error(`Typeform API returned an error: ${formResult.description}`)
}

form.id = formResult.id
Expand Down

0 comments on commit 48a439f

Please sign in to comment.