getEntry returns an [object Object] on 404 instead of the custom object
See original GitHub issueHi guys We love the easy use of contentful 💛 But we find a problem when we try to catch the specific error when an entry does not exists and we realize that the sdk is sending us an [object Object] as a message in the error.
Doing findings over your library (sorry for that) we found that in the line 69 of the file
lib/create-contentful-api.js
you guys are sending a custom object
const notFoundError = (id) => {
return new Error({
'sys': {
'type': 'Error',
'id': 'NotFound'
},
'message': 'The resource could not be found.',
'details': {
'type': 'Entry',
'id': id,
'environment': getGlobalOptions().environment,
'space': getGlobalOptions().space
}
})
But in the error API of NodeJS says that the only parameter that the error receive will be parsed as a string https://nodejs.org/api/errors.html#errors_system_errors
In order to pass an object to the error message it have to be explicit, so if you do
const error = new Error('The resource could not be found.');
error.message = {
sys': {
'type': 'Error',
'id': 'NotFound'
},
'details': {
'type': 'Entry',
'id': id,
'environment': getGlobalOptions().environment,
'space': getGlobalOptions().space
}
}
I think will be the espected behavior from the sdk
Expected Behavior
Error object in the message
Actual Behavior
The string [object, Object]
Possible Solution
I can raise the pull request haha but mostly the one that I put in the top
Steps to Reproduce
Getting any entry with valid env and space
Context
We try to catch the error from diferente sources (our api and yours) and we try to handle the errors differently
Environment
Node v10.8.0 Contentful v7.0.0
Regards
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
@phoebeschmidt @Khaledgarbaya Hmm, I guess we have to
JSON.stringify()
the object to stay aligned how other error messages are handled at the moment.(Even though we are about to change that soon or later for better developer experience)
WDYT?
Thanks 💃