Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
a.strictEqual(typeof line.name, 'string', name + '.name must be a string')
a.ok(line.name.length > 0, name + '.name can\'t be empty')
// skipping line validation here
// see https://github.com/derhuerst/hafas-client/issues/8#issuecomment-355839965
if (is.undefined(line.mode) || is.null(line.mode)) {
console.error(`ÖBB: Missing \`mode\` for line ${line.name} (at ${name}).`)
}
if (!is.undefined(line.subMode)) {
a.fail(name + '.subMode is reserved an should not be used for now')
}
// todo: routes
if (!is.null(line.operator) && !is.undefined(line.operator)) {
validate(['operator'], line.operator, name + '.operator')
}
}
const validateLineWithoutMode = (validate, line, name) => {
validateItem(line, name)
a.strictEqual(line.type, 'line', name + '.type must be `line`')
validateReference(line.id, name + '.id')
a.strictEqual(typeof line.name, 'string', name + '.name must be a string')
a.ok(line.name.length > 0, name + '.name can\'t be empty')
// skipping line validation here
// see https://github.com/derhuerst/hafas-client/issues/8#issuecomment-355839965
if (is.undefined(line.mode) || is.null(line.mode)) {
console.error(`ÖBB: Missing \`mode\` for line ${line.name} (at ${name}).`)
}
if (!is.undefined(line.subMode)) {
a.fail(name + '.subMode is reserved an should not be used for now')
}
// todo: routes
if (!is.null(line.operator) && !is.undefined(line.operator)) {
validate(['operator'], line.operator, name + '.operator')
}
}
setImmediate(async () => {
try {
// Convert buffer to stream to receive upload progress events (#322)
const {body} = options;
if (is.buffer(body)) {
options.body = toReadableStream(body);
uploadBodySize = body.length;
} else {
uploadBodySize = await getBodySize(options);
}
if (is.undefined(options.headers['content-length']) && is.undefined(options.headers['transfer-encoding'])) {
if ((uploadBodySize > 0 || options.method === 'PUT') && !is.null(uploadBodySize)) {
options.headers['content-length'] = uploadBodySize;
}
}
for (const hook of options.hooks.beforeRequest) {
// eslint-disable-next-line no-await-in-loop
await hook(options);
}
requestUrl = options.href || (new URL(options.path, urlLib.format(options))).toString();
await get(options);
} catch (error) {
emitError(error);
}
});
ee.on('response', res => {
const stream = is.null(opts.encoding) ? getStream.buffer(res) : getStream(res, opts);
stream
.catch(err => reject(new got.ReadError(err, opts)))
.then(data => {
const statusCode = res.statusCode;
const limitStatusCode = opts.followRedirect ? 299 : 399;
res.body = data;
if (opts.json && res.body) {
try {
res.body = JSON.parse(res.body);
} catch (err) {
if (statusCode >= 200 && statusCode < 300) {
throw new got.ParseError(err, statusCode, opts, data);
}
ee.on('response', res => {
const stream = is.null(opts.encoding) ? getStream.buffer(res) : getStream(res, opts);
stream
.catch(err => reject(new got.ReadError(err, opts)))
.then(data => {
const statusCode = res.statusCode;
const limitStatusCode = opts.followRedirect ? 299 : 399;
res.body = data;
if (opts.json && res.body) {
try {
res.body = JSON.parse(res.body);
} catch (err) {
if (statusCode >= 200 && statusCode < 300) {
throw new got.ParseError(err, statusCode, opts, data);
}