fix: Groovy脚本JSON解析加try-catch避免API返回格式异常时报错
This commit is contained in:
@@ -6,7 +6,12 @@ final String API_BASE = "https://api.m-team.io"
|
|||||||
|
|
||||||
Map parse(String content, String url) {
|
Map parse(String content, String url) {
|
||||||
def slurp = new groovy.json.JsonSlurper()
|
def slurp = new groovy.json.JsonSlurper()
|
||||||
def root = slurp.parseText(content)
|
def root
|
||||||
|
try {
|
||||||
|
root = slurp.parseText(content)
|
||||||
|
} catch (e) {
|
||||||
|
return [pageName: '解析失败', message: "JSON 解析异常: ${e.message}"]
|
||||||
|
}
|
||||||
|
|
||||||
if (url.contains('/api/member/profile'))
|
if (url.contains('/api/member/profile'))
|
||||||
return parseProfile(root?.data)
|
return parseProfile(root?.data)
|
||||||
|
|||||||
Reference in New Issue
Block a user