question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getEntry returns an [object Object] on 404 instead of the custom object

See original GitHub issue

Hi 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:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
axe312gercommented, Aug 23, 2018

@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?

0reactions
japiercommented, Aug 24, 2018

Thanks 💃

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - How to fix a 404 error when the object does exist?
app.patch(...) means that it will respond to PATCH request only. However, here is no backend code that responds to GET request.
Read more >
Rest.li server user guide - LinkedIn Open Source
The returned UpdateResponse object indicates the HTTP status code to be returned. @ RestMethod.Delete may be used to indicate a delete method instead...
Read more >
Getting 404 Error when trying to create a Lead object in ...
I'm sending a POST request from a connected app to try and create a Lead object in my company's dashboard. Here is the...
Read more >
API Reference - Astro Documentation
It's asynchronous, and returns an array of the exports from matching files. ... Astro.props is an object containing any values that have been...
Read more >
Object prefix at the end of Sites or Community URLs results in ...
Salesforce has a large number of these 3 character prefixes that are reserved and will return a 404 instead of redirecting to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found