Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async create (data, params) {
debug('Requesting create() remote service on path ' + this.path, data, params)
try {
const result = await this.requester.send({ type: 'create', data, params })
debug('Successfully create() remote service on path ' + this.path)
return result
} catch (error) {
throw convert(error)
}
}
async update (id, data, params) {
debug('Requesting update() remote service on path ' + this.path, id, data, params)
try {
const result = await this.requester.send({ type: 'update', id, data, params })
debug('Successfully update() remote service on path ' + this.path)
return result
} catch (error) {
throw convert(error)
}
}
async remove (id, params) {
debug('Requesting remove() remote service on path ' + this.path, id, params)
try {
const result = await this.requester.send({ type: 'remove', id, params })
debug('Successfully remove() remote service on path ' + this.path)
return result
} catch (error) {
throw convert(error)
}
}
}
args.push(function (error: any, data: any) {
error = convert(error);
clearTimeout(timeoutId);
return error ? reject(error) : resolve(data);
});
async find (params) {
debug('Requesting find() remote service on path ' + this.path, params)
try {
const result = await this.requester.send({ type: 'find', params })
debug('Successfully find() remote service on path ' + this.path)
return result
} catch (error) {
throw convert(error)
}
}
async get (id, params) {
debug('Requesting get() remote service on path ' + this.path, id, params)
try {
const result = await this.requester.send({ type: 'get', id, params })
debug('Successfully get() remote service on path ' + this.path)
return result
} catch (error) {
throw convert(error)
}
}
async patch (id, data, params) {
debug('Requesting patch() remote service on path ' + this.path, id, data, params)
try {
const result = await this.requester.send({ type: 'patch', id, data, params })
debug('Successfully patch() remote service on path ' + this.path)
return result
} catch (error) {
throw convert(error)
}
}
function toError (error) {
if (error.code === 'ECONNREFUSED') {
throw new Unavailable(error.message, _.pick(error, 'address', 'port', 'config'));
}
throw convert(error);
}