feat(proxy/api): returns raw errors

Similar to dd5e11e83
This commit is contained in:
Julien Fontanet 2022-08-23 11:08:25 +02:00
parent e9b90caa3a
commit ae373c3e77
2 changed files with 15 additions and 2 deletions

View File

@ -1,4 +1,4 @@
import { format, parse, MethodNotFound } from 'json-rpc-protocol'
import { format, parse, MethodNotFound, JsonRpcError } from 'json-rpc-protocol'
import * as errors from 'xo-common/api-errors.js'
import Ajv from 'ajv'
import asyncIteratorToStream from 'async-iterator-to-stream'
@ -78,7 +78,19 @@ export default class Api {
const { method, params } = body
warn('call error', { method, params, error })
ctx.set('Content-Type', 'application/json')
ctx.body = format.error(body.id, error)
let e = error
if (error != null && typeof error.toJsonRpcError !== 'function') {
const { message, ...data } = error
// force these entries even if they are not enumerable
data.code = error.code
data.stack = error.stack
e = new JsonRpcError(error.message, undefined, data)
}
ctx.body = format.error(body.id, e)
return
}

View File

@ -32,6 +32,7 @@
- @xen-orchestra/backups patch
- @xen-orchestra/fs major
- @xen-orchestra/proxy minor
- vhd-lib major
- xo-vmdk-to-vhd patch
- xo-server minor