Skip to content

Commit 224b68c

Browse files
committed
api 오류처리
1 parent c61a079 commit 224b68c

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

src/main/apis/tistory-api.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,18 +218,28 @@ const _uploadFile = (accessToken, blogName, fileBlob, fileOption) => {
218218
const validateAuthInfo = (auth) => auth && auth.access_token
219219

220220
const fetchAccount = async (auth) => {
221-
const userRes = await fetchUser(auth.authInfo)
222-
const blogRes = await fetchBlogInfo(auth.authInfo)
221+
let user = {
222+
name: "tistory",
223+
image: null
224+
}
225+
let blogs = []
226+
try {
227+
const userRes = await fetchUser(auth.authInfo)
228+
const blogRes = await fetchBlogInfo(auth.authInfo)
229+
user.name = userRes.tistory.item.name,
230+
user.image = userRes.tistory.item.image
231+
blogs = blogRes.tistory.item.blogs
232+
} catch (e) {
233+
console.error(e)
234+
user.name = "불러오기 오류"
235+
}
223236
return {
224237
auth: {
225238
uuid: auth.uuid,
226239
provider: auth.provider
227240
},
228-
user: {
229-
name: userRes.tistory.item.name,
230-
image: userRes.tistory.item.image
231-
},
232-
blogs: blogRes.tistory.item.blogs.map(blog => ({
241+
user: user,
242+
blogs: blogs.map(blog => ({
233243
name: blog.name,
234244
url: blog.secondaryUrl == ''? blog.url : blog.secondaryUrl,
235245
title: blog.title,

src/main/apis/tumblr-api.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,27 @@ const savePost = async (auth, blogName, post) => {
125125
const validateAuthInfo = (auth) => auth && auth.token
126126

127127
const fetchAccount = async (auth) => {
128-
const res = await fetchUser(auth.authInfo)
128+
let blogs = []
129+
let username = ""
130+
try {
131+
const res = await fetchUser(auth.authInfo)
132+
username = res.user.name
133+
blogs = res.user.blogs
134+
} catch (e) {
135+
username = "불러오기 오류"
136+
console.error(e)
137+
}
138+
129139
return {
130140
auth: {
131141
uuid: auth.uuid,
132142
provider: auth.provider
133143
},
134144
user: {
135-
name: res.user.name,
145+
name: username,
136146
image: null
137147
},
138-
blogs: res.user.blogs.map(blog => ({
148+
blogs: blogs.map(blog => ({
139149
name: blog.name,
140150
url: blog.url,
141151
title: blog.title,

0 commit comments

Comments
 (0)