本文整理汇总了TypeScript中Boom.create函数的典型用法代码示例。如果您正苦于以下问题:TypeScript create函数的具体用法?TypeScript create怎么用?TypeScript create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: topic
@get('/{topic}/{page?}')
async topic(request: hapi.Request, reply: hapi.IReply) {
let topicSlug: string = request.params['topic'];
let page = (!isNaN(Number(request.params['page']))) ? Number(request.params['page']) : 1;
let limit = 10;
let offset = page <= 1 ? 0 : (page * limit) - limit;
try {
let topics = await getTopics();
let topic = await getTopic(topicSlug);
let posts = await getPostsByTopic(topicSlug, true, 'DESC', offset, limit);
let totalPosts = posts['count'];
reply.view('category', {
title: topic.getDataValue('topic'),
description: '',
posts,
topics,
pagination: {
basePath: `/topic/${topicSlug}`,
pageCount: Math.ceil(totalPosts / limit),
page
}
});
} catch (err) {
if (err.name === 'SequelizeConnectionError') {
reply(boom.create(500, 'Bad Connection'));
} else {
reply(boom.create(500, err.message));
}
}
}
示例2: reply
command.catch((err: Error) => {
if (err.name === 'SequelizeConnectionError') {
reply(boom.create(503, 'Bad Connection'));
} else {
reply(boom.create(400, err.message));
}
});
示例3: handleRequestError
export function handleRequestError(friend: User, e: Error, log: any, looped?: boolean, reply?: h.IReply) {
let code: number = 500; // Default value
let message: string = ''; // Default value
if(e instanceof r.RequestError) {
code = e.error.code;
} else if(e instanceof r.StatusCodeError) {
code = e.statusCode;
}
if(e instanceof r.StatusCodeError && e.statusCode === 400) {
message = 'This usually means the API was badly implemented either on the current instance or on the friend\'s.';
} else if(e instanceof r.StatusCodeError && e.statusCode === 401) {
message = 'This can happen because of a bad implementation of the Vinimay API on either side, or because of an instance domain mismatch between the two instances\' databases.';
} else if(e instanceof r.StatusCodeError && e.statusCode === 500) {
message = 'This can happen because of a bug in the remote instance\'s code or a bad implentation of the Vinimay API on its side.'
} else if(e instanceof r.StatusCodeError) {
// Some errors are thrown willingly to be sent to the client
if(reply && !looped) return reply(b.create(e.statusCode));
else return;
} else if(!(e instanceof r.RequestError)) {
log.error(e);
if(reply && !looped) return reply(b.wrap(e));
else return;
}
// Default behaviour
if(code) log.warn('Got a ' + code + ' when querying ' + friend)
else log.error(e);
if(message.length) log.warn(message);
if(reply && !looped) reply(b.serverUnavailable());
}
示例4: deletePostApi
@route('delete', '/{id}')
@config({
auth: 'jwt'
})
async deletePostApi(request: hapi.Request, reply: hapi.IReply) {
let postId = Number(request.params['id']);
try {
await deletePost(postId);
reply({ message: 'Post Deleted' });
} catch (exc) {
if (exc.name === 'SequelizeConnectionError') {
reply(boom.create(503, 'Bad Connection'));
} else {
reply(boom.create(503, exc.message));
}
}
}
示例5: download
@get('/{token?}')
async download(request: hapi.Request, reply: hapi.IReply) {
let token: string = request.params['token'];
try {
let file = await getDownloadRequest(token);
reply.redirect(file);
} catch (err) {
reply(boom.create(500, err || err.message));
}
}
示例6: rssTopic
@get('/{topic}/feed/rss')
async rssTopic(request: hapi.Request, reply: hapi.IReply) {
let topicSlug: string = request.params['topic'];
let host = request.headers['host'];
let permalink = `/topic/${topicSlug}/feed/rss`;
try {
let topic = await getTopic(topicSlug);
let posts = await topic.getPosts({ where: { 'publishedAt': { $ne: null } } });
let title = `CSG Pro ${topic.getDataValue('topic')} Posts`;
let description = `Lastest posts about "${topic.getDataValue('topic')}"`;
reply.view('rss', { posts, host, title, description, permalink }, { layout: 'blank' }).type('text/xml');
} catch (err) {
if (err.name === 'SequelizeConnectionError') {
reply(boom.create(500, 'Bad Connection'));
} else {
reply(boom.create(500, err.message));
}
}
}
示例7: getTopicApi
@get('/{id}')
@config({
auth: 'jwt'
})
async getTopicApi(request: hapi.Request, reply: hapi.IReply) {
let { id } = request.params;
let topicId = Number(id);
try {
let topic = await getTopic(topicId);
reply({ data: topic });
} catch (exc) {
let error = exc && exc.message ? exc.message : exc;
console.error(exc && exc.stack ? exc.stack : exc);
if (exc.name === 'SequelizeConnectionError') {
reply(boom.create(503, 'Bad Connection'));
} else {
reply(boom.create(503, error));
}
}
}
示例8: getPostsApi
@get('/')
@config({
auth: 'jwt'
})
async getPostsApi(request: hapi.Request, reply: hapi.IReply) {
let {category, filter, sort, offset, limit} = request.query;
limit = ((isNaN(limit)) ? undefined : +limit);
let where: sequelize.WhereOptions = {};
try {
if (category) {
let postCategory = await PostCategory.findOne({ where: { slug: category } });
where['categoryId'] = postCategory.getDataValue('id');
}
switch (filter) {
case 'published':
where['publishedAt'] = { $gt: new Date('1993-01-01') };
break;
case 'unpublished':
where['publishedAt'] = null;
break;
}
let posts = (await Post.findAndCountAll({ where, offset, limit, order: [[ 'id', sort || 'DESC' ]], include: [{ all: true }] })).rows;
reply({ data: posts });
} catch (exc) {
if (exc.name === 'SequelizeConnectionError') {
reply(boom.create(503, 'Bad Connection'));
} else {
reply(boom.create(503, exc.message));
}
}
}
示例9: doesBlobExist
doesBlobExist(filename, (error, result, response) => {
if (error) {
reply(boom.create(500, error.message));
return;
}
if (!result.exists) {
reply(boom.notFound());
return;
}
getBlobProperties(filename, (error, result, response) => {
let contentType = result.contentSettings.contentType;
Request(url).on('response', (response) => {
reply(response).header('Content-Type', contentType);
});
});
});
示例10: reply
}, (error: HttpQueryError) => {
if ( 'HttpQueryError' !== error.name ) {
throw error;
}
if ( true === error.isGraphQLError ) {
return reply(error.message).code(error.statusCode).type('application/json');
}
const err = Boom.create(error.statusCode);
err.output.payload.message = error.message;
if ( error.headers ) {
Object.keys(error.headers).forEach((header) => {
err.output.headers[header] = error.headers[header];
});
}
return reply(err);
});