Skip to content

Commit

Permalink
fix: Errors thrown in async provider methods do not send the JSONRPC …
Browse files Browse the repository at this point in the history
…error response (#143)
  • Loading branch information
kpears201 authored Nov 1, 2023
1 parent 4de8944 commit ec8e259
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions languages/javascript/src/shared/ProvideManager/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ const provide = function(capability, provider) {
const response = {
correlationId: request.correlationId
}
let handleError = error => {
response.error = {
code: error.code || 1000, // todo: should be some reserved code for "Unknown"
message: error.message || `An error occured while calling provided ${method} method.`
}

if (error.data) {
response.error.data = JSON.parse(JSON.stringify(error.data))
}

Transport.send(module, `${method}Error`, response)
}

try {
const result = provider[method].apply(provider, providerCallArgs)
Expand All @@ -107,19 +119,10 @@ const provide = function(capability, provider) {
}

Transport.send(module, `${method}Response`, response)
})
}).catch(err => handleError(err))
}
catch(error) {
response.error = {
code: error.code || 1000, // todo: should be some reserved code for "Unknown"
message: error.message || `An error occured while calling provided ${method} method.`
}

if (error.data) {
response.error.data = JSON.parse(JSON.stringify(error.data))
}

Transport.send(module, `${method}Error`, response)
handleError(error)
}
})
})
Expand Down

0 comments on commit ec8e259

Please sign in to comment.