UNPKG

dobo-restproxy

Version:
31 lines (27 loc) 751 B
async function factory (pkgName) { const me = this return class DoboRestproxy extends this.lib.BajoPlugin { constructor () { super(pkgName, me.app) this.alias = 'dbrpx' this.dependencies = ['dobo', 'bajo-extra'] this.config = { } } fetch = async (url, opts = {}, extra = {}) => { const { fetchUrl } = this.app.bajoExtra extra.rawResponse = true const resp = await fetchUrl(url, opts, extra) const result = await resp.json() if (!resp.ok) { throw this.error(result.message, { noTrans: true, statusCode: resp.status, success: false }) } return result } } } export default factory