From e5f986a95932ae14a36590bc4dcf22f2acb025f8 Mon Sep 17 00:00:00 2001 From: lijinglue Date: Mon, 26 Feb 2018 21:12:42 +0800 Subject: [PATCH] checking if return is valid before creating the blog attr in note --- browser/main/NoteList/index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index 3db88dd1..7075c0ef 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -489,7 +489,7 @@ class NoteList extends React.Component { click: this.cloneNote.bind(this) })) if (note.type === 'MARKDOWN_NOTE') { - if (note.blog) { + if (note.blog && note.blog.blogLink && note.blog.blogId) { menu.append(new MenuItem({ label: updateLabel, click: this.publishMarkdown.bind(this) @@ -697,7 +697,7 @@ class NoteList extends React.Component { let url = '' let method = '' - if (firstNote.blog) { + if (firstNote.blog && firstNote.blog.blogId) { url = `${address}${WP_POST_PATH}/${firstNote.blog.blogId}` method = 'PUT' } else { @@ -714,6 +714,9 @@ class NoteList extends React.Component { } }).then(res => res.json()) .then(response => { + if (_.isNil(response.link) || _.isNil(response.id)) { + return Promise.reject(); + } firstNote.blog = { blogLink: response.link, blogId: response.id @@ -721,7 +724,8 @@ class NoteList extends React.Component { this.save(firstNote) this.confirmPublish(firstNote) }) - .catch(() => { + .catch((error) => { + console.error(error) this.confirmPublishError() }) } @@ -753,7 +757,6 @@ class NoteList extends React.Component { openBlog (note) { const { shell } = electron - console.log(note) shell.openExternal(note.blog.blogLink) }