Skip to content

Commit

Permalink
emergency patch: fixed an issue where runtime error in parse response…
Browse files Browse the repository at this point in the history
… throws
  • Loading branch information
tinyAdapter committed May 30, 2020
1 parent eb3d9a3 commit 4d7382a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/main/translate/Api.ts
Expand Up @@ -116,7 +116,11 @@ export default class Api implements yuki.Translator {
const scriptString = this.config.responseBodyPattern
.substring(1)
.replace('%RESPONSE%', `result = response`)
vm.runInNewContext(scriptString, this.responseVmContext)
try {
vm.runInNewContext(scriptString, this.responseVmContext)
} catch (e) {
return `ERR: ${e}`
}
return this.responseVmContext.result
}

Expand Down
2 changes: 1 addition & 1 deletion test/unit/specs/main/Api.spec.ts
Expand Up @@ -59,7 +59,7 @@ describe('Api', () => {
expect(translations.translations.googleCN).to.equal('如果捕获了尤马坤,则为210日元。我知道了 ...')
expect(translations.translations.caiyun).to.be.oneOf([
'攻下悠真的话是210日元吗。 原来如此',
undefined
"ERR: TypeError: Cannot read property 'target' of undefined"
])
} catch (e) {
return done(e)
Expand Down

0 comments on commit 4d7382a

Please sign in to comment.