Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getRequestOptionsWithData(data: any, options: SearchOptions) {
if (isPlainObject(data) || Array.isArray(data)) {
return Object.assign({}, options, { body: data });
}
return Object.assign({}, options, { body: data, json: false });
}
function getErrorFromResponse(response: any) {
let { body } = response;
if (body && isString(body)) {
try {
body = JSON.parse(body);
} catch (err) {
return { message: body };
}
}
if (body && isPlainObject(body)) {
if (isString(body.error)) {
return {
message: body.error
};
}
return {
message: body.message,
code: body.error
};
}
return {};
}
async errors(exId?: string | SearchQuery, opts?: SearchQuery): Promise {
const options: SearchQuery = {};
if (isString(exId)) {
if (isPlainObject(opts)) {
options.query = opts;
}
return this.get(`/ex/${exId}/errors`, options as SearchOptions);
}
if (isPlainObject(exId)) {
options.query = exId;
}
return this.get('/ex/errors', options as SearchOptions);
}