UNPKG

xen-api

Version:
36 lines (30 loc) 786 B
import jsonRpc from './json-rpc.mjs' import UnsupportedTransport from './_UnsupportedTransport.mjs' import xmlRpc from './xml-rpc.mjs' const factories = [jsonRpc, xmlRpc] const { length } = factories export default opts => { let i = 0 let call function create() { const current = factories[i++](opts) if (i < length) { const currentI = i call = (method, args) => current(method, args).catch(error => { if (error instanceof UnsupportedTransport) { if (currentI === i) { // not changed yet create() } return call(method, args) } throw error }) } else { call = current } } create() return (method, args) => call(method, args) }