Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 {};
}
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
async txt(
name = '',
version = '',
query: TxtSearchParams = {},
searchOptions: SearchOptions = {}
): Promise {
if (name && !isString(name)) throw new TSError('name must be of type string');
if (version && !isString(version)) throw new TSError('version must be of type string');
const options = Object.assign({ json: false }, searchOptions, { query });
const pathing = path.join('/txt/assets', name, version);
return super.get(pathing, options);
}
}
function validateRequestOptions(endpoint: string, _options?: SearchOptions) {
if (!endpoint) {
return 'endpoint must not be empty';
}
if (!isString(endpoint)) {
return 'endpoint must be a string';
}
return null;
}
async getAsset(name: string, version = '', searchOptions: SearchOptions = {}): Promise {
if (!name || !isString(name)) throw new TSError('name is required, and must be of type string');
if (version && !isString(version)) throw new TSError('version if provided must be of type string');
const pathing = path.join('/assets', name, version);
return super.get(pathing, searchOptions);
}