提交 8cd5493e 编写于 作者: Q qiang

fix(App): 修复部分 API 缺失详细错误信息的问题

上级 0dfd05e3
......@@ -58,7 +58,7 @@ export function getProvider ({
providers[service]((err, provider) => {
if (err) {
invoke(callbackId, {
errMsg: 'getProvider:fail:' + err.message
errMsg: 'getProvider:fail ' + err.message
})
} else {
invoke(callbackId, {
......@@ -70,7 +70,7 @@ export function getProvider ({
})
} else {
invoke(callbackId, {
errMsg: 'getProvider:fail:服务[' + service + ']不支持'
errMsg: 'getProvider:fail 服务[' + service + ']不支持'
})
}
}
......@@ -20,6 +20,8 @@ function getService (provider) {
*/
export function login (params, callbackId) {
const provider = params.provider || 'weixin'
const errorCallback = warpPlusErrorCallback(callbackId, 'login')
getService(provider).then(service => {
function login () {
service.login(res => {
......@@ -29,12 +31,7 @@ export function login (params, callbackId) {
authResult: authResult,
errMsg: 'login:ok'
})
}, err => {
invoke(callbackId, {
code: err.code,
errMsg: 'login:fail:' + err.message
})
}, provider === 'apple' ? { scope: 'email' } : params.univerifyStyle || {})
}, errorCallback, provider === 'apple' ? { scope: 'email' } : params.univerifyStyle || {})
}
// 先注销再登录
// apple登录logout之后无法重新触发获取email,fullname;一键登录无logout
......@@ -43,12 +40,7 @@ export function login (params, callbackId) {
} else {
service.logout(login, login)
}
}).catch(err => {
invoke(callbackId, {
code: err.code || '',
errMsg: 'login:fail:' + err.message
})
})
}).catch(errorCallback)
}
export function getUserInfo (params, callbackId) {
......
......@@ -2,29 +2,27 @@ import {
invoke
} from '../../bridge'
import {
warpPlusErrorCallback
} from '../util'
export function requestPayment (params, callbackId) {
const provider = params.provider
const errorCallback = warpPlusErrorCallback(callbackId, 'requestPayment')
plus.payment.getChannels(services => {
const service = services.find(({
id
}) => id === provider)
if (!service) {
invoke(callbackId, {
errMsg: 'requestPayment:fail:支付服务[' + provider + ']不存在'
errMsg: 'requestPayment:fail 支付服务[' + provider + ']不存在'
})
} else {
plus.payment.request(service, params.orderInfo, res => {
res.errMsg = 'requestPayment:ok'
invoke(callbackId, res)
}, err => {
invoke(callbackId, {
errMsg: 'requestPayment:fail:' + err.message
})
})
}, errorCallback)
}
}, err => {
invoke(callbackId, {
errMsg: 'requestPayment:fail:' + err.message
})
})
}, errorCallback)
}
......@@ -3,7 +3,8 @@ import {
} from '../constants'
import {
getRealPath
getRealPath,
warpPlusErrorCallback
} from '../util'
import {
......@@ -82,19 +83,13 @@ const parseParams = (args, callbackId, method) => {
}
const sendShareMsg = function (service, params, callbackId, method = 'share') {
service.send(
params,
() => {
invoke(callbackId, {
errMsg: method + ':ok'
})
},
err => {
invoke(callbackId, {
errMsg: method + ':fail:' + err.message
})
}
)
const errorCallback = warpPlusErrorCallback(callbackId, method)
service.send(params, () => {
invoke(callbackId, {
errMsg: method + ':ok'
})
}, errorCallback)
}
export function shareAppMessageDirectly ({
......@@ -117,37 +112,24 @@ export function shareAppMessageDirectly ({
'shareAppMessageDirectly'
)
}
const errorCallback = warpPlusErrorCallback(callbackId, 'shareAppMessageDirectly')
if (useDefaultSnapshot) {
const pages = getCurrentPages()
const webview = plus.webview.getWebviewById(pages[pages.length - 1].__wxWebviewId__ + '')
if (webview) {
const bitmap = new plus.nativeObj.Bitmap()
webview.draw(
bitmap,
() => {
const fileName = TEMP_PATH + '/share/snapshot.jpg'
bitmap.save(
fileName, {
overwrite: true,
format: 'jpg'
},
() => {
imageUrl = fileName
goShare()
},
err => {
invoke(callbackId, {
errMsg: 'shareAppMessageDirectly:fail:' + err.message
})
}
)
},
err => {
invoke(callbackId, {
errMsg: 'shareAppMessageDirectly:fail:' + err.message
})
}
)
webview.draw(bitmap, () => {
const fileName = TEMP_PATH + '/share/snapshot.jpg'
bitmap.save(
fileName, {
overwrite: true,
format: 'jpg'
}, () => {
imageUrl = fileName
goShare()
}, errorCallback)
}, errorCallback)
} else {
goShare()
}
......@@ -158,73 +140,62 @@ export function shareAppMessageDirectly ({
export function share (params, callbackId, method = 'share') {
params = parseParams(params, callbackId, method)
const errorCallback = warpPlusErrorCallback(callbackId, method)
if (typeof params === 'string') {
return invoke(callbackId, {
errMsg: method + ':fail:' + params
errMsg: method + ':fail ' + params
})
}
const provider = params.provider
plus.share.getServices(
services => {
const service = services.find(({
id
}) => id === provider)
if (!service) {
invoke(callbackId, {
errMsg: method + ':fail:分享服务[' + provider + ']不存在'
})
} else {
if (service.authenticated) {
sendShareMsg(service, params, callbackId)
} else {
service.authorize(
() => sendShareMsg(service, params, callbackId),
err => {
invoke(callbackId, {
errMsg: method + ':fail:' + err.message
})
}
)
}
}
},
err => {
plus.share.getServices(services => {
const service = services.find(({
id
}) => id === provider)
if (!service) {
invoke(callbackId, {
errMsg: method + ':fail:' + err.message
errMsg: method + ':fail 分享服务[' + provider + ']不存在'
})
} else {
if (service.authenticated) {
sendShareMsg(service, params, callbackId)
} else {
service.authorize(
() => sendShareMsg(service, params, callbackId),
errorCallback
)
}
}
)
}, errorCallback)
}
export function shareWithSystem (params, callbackId, method = 'shareWithSystem') {
let {
type,
imageUrl,
summary: content,
href
export function shareWithSystem (params, callbackId, method = 'shareWithSystem') {
let {
type,
imageUrl,
summary: content,
href
} = params
type = type || 'text'
const allowedTypes = ['text', 'image']
if (allowedTypes.indexOf(type) < 0) {
invoke(callbackId, {
errMsg: method + ':fail:分享参数 type 不正确'
})
}
if (typeof imageUrl === 'string' && imageUrl) {
imageUrl = getRealPath(imageUrl)
const allowedTypes = ['text', 'image']
const errorCallback = warpPlusErrorCallback(callbackId, method)
if (allowedTypes.indexOf(type) < 0) {
invoke(callbackId, {
errMsg: method + ':fail 分享参数 type 不正确'
})
}
if (typeof imageUrl === 'string' && imageUrl) {
imageUrl = getRealPath(imageUrl)
}
plus.share.sendWithSystem({
type,
pictures: imageUrl && [imageUrl],
content,
href
plus.share.sendWithSystem({
type,
pictures: imageUrl && [imageUrl],
content,
href
}, function (res) {
invoke(callbackId, {
errMsg: method + ':ok'
})
}, function (err) {
invoke(callbackId, {
errMsg: method + ':fail:' + err.message
})
})
}
}, errorCallback)
}
......@@ -190,9 +190,11 @@ export function warpPlusSuccessCallback (callbackId, neme) {
export function warpPlusErrorCallback (callbackId, neme, errMsg) {
return function errorCallback (error) {
error = error || {}
const code = error.code || 0
invoke(callbackId, {
errMsg: `${neme}:fail ${error.message || errMsg || ''}`,
errCode: error.code || 0
errCode: code,
code
})
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册