Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Cannot read property 'map' of undefined" in Notes.js after unhandled server error #51

Open
zudljk opened this issue Sep 5, 2020 · 4 comments

Comments

@zudljk
Copy link

zudljk commented Sep 5, 2020

When a request to resolve a note fails on the server side (e.g. 400 Bad Request), a JSON will be returned that doesn't a "results" field.

This was the payload returned from the server from at least one of the notes in my iCloud account:

{
  "uuid" : "2487d368-fc70-410d-8c0b-ec957399b58a",
  "serverErrorCode" : "BAD_REQUEST",
  "reason" : "BadRequestException: missing required field 'value'"
}

Therefore, this line will produce a TypeError since result.results will be undefined:

const records = result.results.map(res => res.rootRecord).map(record => {

Exception stack trace:

TypeError: Cannot read property 'map' of undefined
    at Request._callback (y:\src\icloudapi-test\node_modules\apple-icloud\resources\apps\Notes.js:139:40)
    at Request.self.callback (y:\src\icloudapi-test\node_modules\request\request.js:185:22)
    at Request.emit (events.js:182:13)
    at Request.<anonymous> (y:\src\icloudapi-test\node_modules\request\request.js:1154:10)
    at Request.emit (events.js:182:13)
    at IncomingMessage.<anonymous> (y:\src\icloudapi-test\node_modules\request\request.js:1076:12)
    at Object.onceWrapper (events.js:275:13)
    at IncomingMessage.emit (events.js:187:15)
    at endReadableNT (_stream_readable.js:1091:14)
    at process._tickCallback (internal/process/next_tick.js:174:19)

The reason was that at least one of my notes fetched by myCloud.Notes.fetch() had no "shortGUID" field.
Filtering out this note fixed the error for me, but there should be a general handling of Bad Request errors.

Apart from that, thanks for the great work on this project!

@JOJ0
Copy link

JOJ0 commented Oct 14, 2020

Hi, I am experiencing the same error, and thus trying to figure out where and what the shortGUID field is but it seems I can't find it.
Trying stuff like this:

const notes = myCloud.Notes.fetch();
notes.on("data", async zone => {
       ....
       .... 
        console.log(myNote.fields.Note.value['recordName'])
        console.log(myNote.fields.Note.value)
        console.log(myNote)
}

Maybe I am on the wrong track but would like to find notes where this field is missing and filter them out as suggested. Where inside "myNote" should this field be located?

Thanks!

@JOJ0
Copy link

JOJ0 commented Nov 4, 2020

Hi @zudljk sorry for bothering you but this is proably an easy one for you ^

I would like to use the same workaround as you did but can't locate the shortGUID anywhere in my objects. It drive's me kind of crazy - and yes I am not too familiar with javascript - coming from python. Well anyway, maybe you could give me some heads up. Thanks in advance!

Jojo

@zudljk
Copy link
Author

zudljk commented Nov 6, 2020

Hi @JOJ0, sorry for the late answer, as far as I remember, the shortGUID property is directly below the note object itself.
At least that's where I check for it in my own project (https://github.com/zudljk/inotes2md/blob/master/inotes2md.js)

@JOJ0
Copy link

JOJ0 commented Nov 6, 2020

Yes! this is exactely the answer I was looking for! I am sure it will help. I will report my findings here, it might help others too. Will take some time until I get to work on this again. Thanks a lot! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants