1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00

checking if return is valid before creating the blog attr in note

This commit is contained in:
lijinglue
2018-02-26 21:12:42 +08:00
parent aef603ed8c
commit e5f986a959

View File

@@ -489,7 +489,7 @@ class NoteList extends React.Component {
click: this.cloneNote.bind(this) click: this.cloneNote.bind(this)
})) }))
if (note.type === 'MARKDOWN_NOTE') { if (note.type === 'MARKDOWN_NOTE') {
if (note.blog) { if (note.blog && note.blog.blogLink && note.blog.blogId) {
menu.append(new MenuItem({ menu.append(new MenuItem({
label: updateLabel, label: updateLabel,
click: this.publishMarkdown.bind(this) click: this.publishMarkdown.bind(this)
@@ -697,7 +697,7 @@ class NoteList extends React.Component {
let url = '' let url = ''
let method = '' let method = ''
if (firstNote.blog) { if (firstNote.blog && firstNote.blog.blogId) {
url = `${address}${WP_POST_PATH}/${firstNote.blog.blogId}` url = `${address}${WP_POST_PATH}/${firstNote.blog.blogId}`
method = 'PUT' method = 'PUT'
} else { } else {
@@ -714,6 +714,9 @@ class NoteList extends React.Component {
} }
}).then(res => res.json()) }).then(res => res.json())
.then(response => { .then(response => {
if (_.isNil(response.link) || _.isNil(response.id)) {
return Promise.reject();
}
firstNote.blog = { firstNote.blog = {
blogLink: response.link, blogLink: response.link,
blogId: response.id blogId: response.id
@@ -721,7 +724,8 @@ class NoteList extends React.Component {
this.save(firstNote) this.save(firstNote)
this.confirmPublish(firstNote) this.confirmPublish(firstNote)
}) })
.catch(() => { .catch((error) => {
console.error(error)
this.confirmPublishError() this.confirmPublishError()
}) })
} }
@@ -753,7 +757,6 @@ class NoteList extends React.Component {
openBlog (note) { openBlog (note) {
const { shell } = electron const { shell } = electron
console.log(note)
shell.openExternal(note.blog.blogLink) shell.openExternal(note.blog.blogLink)
} }