Skip to content
This repository has been archived by the owner on Mar 10, 2021. It is now read-only.

Commit

Permalink
refactor(error-handling): don't show special error text on duplicatio…
Browse files Browse the repository at this point in the history
…n errors

the initial idea was to show a special error message that tells the user that the import currently
does not support updating. But if the user did not want to update something in the first place he
would be interested in knowing which field was causing the duplication error. That's why we now show
the original error from the API.
  • Loading branch information
philippspo committed Mar 9, 2016
1 parent 0fbe7c1 commit e3f07ff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
6 changes: 1 addition & 5 deletions src/customer-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,7 @@ export default class CustomerImport {
resolve(customer)
})
.catch((error) => {
const { body } = error
const errorCode = body ? body.errors[0].code : null
if (errorCode === 'DuplicateField') {
return reject('updating customers is not implement yet')
}
// TODO: potentially handle duplicate field error here
return reject(error)
})
})
Expand Down
17 changes: 9 additions & 8 deletions tests/unit/customer-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,15 @@ describe('customer import module', () => {
})

it('should handle existing customers', (done) => {
const error = {
body: {
errors: [{
code: 'DuplicateField'
}]
}
}
const mockCustomerSave = () => {
return Promise.reject({
body: {
errors: [{
code: 'DuplicateField'
}]
}
})
return Promise.reject(error)
}
sinon.stub(importer.client.customers, 'save', mockCustomerSave)
const customer = { email: '[email protected]' }
Expand All @@ -174,7 +175,7 @@ describe('customer import module', () => {
const actual = importer.summary.errors[0]
const expected = {
customer,
error: 'updating customers is not implement yet'
error: error
}
expect(actual).to.deep.equal(expected)
importer.client.customers.save.restore()
Expand Down

0 comments on commit e3f07ff

Please sign in to comment.