本文整理匯總了TypeScript中nightingale-logger.warn函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript warn函數的具體用法?TypeScript warn怎麽用?TypeScript warn使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了warn函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: Error
connection.on('timeout', () => {
logger.warn('timeout', { connectionString });
this.connectionFailed = true;
this.getConnection = () => {
throw new Error('MongoDB connection timeout');
};
});
示例2:
connection.on('error', (err) => {
logger.warn('error', { connectionString, err });
});
示例3: decode
(
{ type, resourceName, json }: EventResourceParams,
callback: Callback,
): void => {
try {
const value = json && decode(json);
switch (type) {
case 'cursor toArray': {
const resource = resourcesService.getCursorResource(resourceName);
resourcesService
.createCursor(resource, socket.user, value)
.then((cursor) => cursor.toArray())
.then((results) => callback(null, encode(results)))
.catch((err) => {
logger.error(type, err);
callback(err.message);
});
break;
}
case 'fetch':
case 'subscribe':
case 'fetchAndSubscribe':
try {
const resource = resourcesService.getServiceResource(
resourceName,
);
logger.info('resource', { type, resourceName, value });
const [key, params, eventName] = value;
if (!key.startsWith('query')) {
throw new Error('Invalid query key');
}
const query = resource.queries[key](params, socket.user);
if (type === 'fetch') {
query
.fetch((result: any) =>
callback(null, result && encode(result)),
)
.catch((err: any) => {
logger.error(type, { err });
callback(err.message || err);
});
} else {
const watcherKey = `${resourceName}__${key}`;
if (openWatchers.has(watcherKey)) {
logger.warn(
'Already have a watcher for this key. Cannot add a new one',
{ watcherKey, key },
);
callback(
'Already have a watcher for this key. Cannot add a new one',
);
return;
}
const watcher = query[type](
(err: Error | null, result: any) => {
if (err) {
logger.error(type, { err });
}
socket.emit(eventName, err, result && encode(result));
},
);
watcher.then(
() => callback(null),
(err: Error) => {
logger.error(type, { err });
callback(err.message);
},
);
const subscribeHook =
resource.subscribeHooks && resource.subscribeHooks[key];
openWatchers.set(watcherKey, { watcher, subscribeHook });
if (subscribeHook) {
subscribeHook.subscribed(socket.user);
}
}
} catch (err) {
logger.error(type, { err });
callback(err.message || err);
}
break;
case 'unsubscribe': {
const [key] = value;
const watcherKey = `${resourceName}__${key}`;
const watcherAndSubscribeHook = openWatchers.get(watcherKey);
if (!watcherAndSubscribeHook) {
logger.warn('tried to unsubscribe non existing watcher', {
key,
});
return callback(null);
}
//.........這裏部分代碼省略.........