本文整理汇总了TypeScript中Boom.notAcceptable函数的典型用法代码示例。如果您正苦于以下问题:TypeScript notAcceptable函数的具体用法?TypeScript notAcceptable怎么用?TypeScript notAcceptable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了notAcceptable函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: createUser
export async function createUser(server: Server, request: Request, reply: IReply)
{
const payload = request.payload as {name: string, username: string, password: string, accountId: string};
const account = await Accounts.Database.get<Account>(payload.accountId.toLowerCase());
if (!account)
{
return reply(notAcceptable(`No account with id of ${payload.accountId} exists.`));
}
// Ensure adding another user won't go over the account's plan limit.
const userCount = await Users.countByAccountId(payload.accountId.toLowerCase());
const plan = findPlan(account.planId);
if (userCount >= plan.totalUsers)
{
return reply(notAcceptable("Account's plan has reached its maximum number of users."));
}
let user: User = {
_id: payload.username,
_rev: undefined,
accountId: payload.accountId.toLowerCase(),
hashedPassword: hashSync(payload.password, 10),
name: payload.name,
}
try
{
const update = await Users.Database.put(user);
if (!update.ok)
{
return reply(expectationFailed("Failed to create user.", update));
}
user._rev = update.rev;
}
catch (e)
{
console.error("Error thrown when creating user", e);
throw e;
}
// Do not reflect the user's hashedPassword.
user.hashedPassword = undefined;
return reply(user).code(201);
}
开发者ID:nozzlegear,项目名称:stages-api,代码行数:50,代码来源:users-routes.ts
示例2: getSearchDsl
export function getSearchDsl(
mappings: IndexMapping,
schema: SavedObjectsSchema,
options: GetSearchDslOptions
) {
const {
type,
search,
defaultSearchOperator,
searchFields,
sortField,
sortOrder,
namespace,
hasReference,
} = options;
if (!type) {
throw Boom.notAcceptable('type must be specified');
}
if (sortOrder && !sortField) {
throw Boom.notAcceptable('sortOrder requires a sortField');
}
return {
...getQueryParams(
mappings,
schema,
namespace,
type,
search,
searchFields,
defaultSearchOperator,
hasReference
),
...getSortingParams(mappings, type, sortField, sortOrder),
};
}
开发者ID:elastic,项目名称:kibana,代码行数:38,代码来源:search_dsl.ts
示例3: function
handler: async function (req, res, next) {
const query: Requests.GetOauthUrl = req.validatedQuery;
const isValidUrl = await Auth.isValidShopifyDomain(req.validatedQuery.shop_domain);
if (!isValidUrl) {
return next(boom.notAcceptable(`${query.shop_domain} is not a valid Shopify shop domain.`));
}
const authUrl = await Auth.buildAuthorizationUrl(Constants.DEFAULT_SCOPES, req.validatedQuery.shop_domain, Constants.SHOPIFY_API_KEY, query.redirect_url);
res.json({ url: authUrl });
return next();
}
开发者ID:nozzlegear,项目名称:Gearworks,代码行数:14,代码来源:shopify.ts
示例4: errorHandlerMiddleware
return async function errorHandlerMiddleware(ctx, next) {
try {
await next();
if (ctx.status === 404) throw Boom.notFound();
} catch (applicationError) {
const err: ApplicationError = applicationError;
let error: Boom<any>;
// Normalize error object
try {
if (!(applicationError instanceof Error)) throw new Error('Cannot handle non-errors as errors');
error = Boom.isBoom(err)
? err
: Boom.boomify(err, {
statusCode: err.status || err.statusCode || undefined,
decorate: err.data,
});
} catch (subError) {
error = Boom.boomify(subError);
}
// Set defaults
let status = Boom.notAcceptable().output.statusCode;
let headers = {};
let body: string | object = Boom.notAcceptable().output.payload.message;
// Check for dev and include dev stuff
if (ctx.app.env !== 'production') {
error.output.payload.additionalDevelopmentData = {
data: error.data || undefined,
stack: error.isServer && error.stack ? error.stack : undefined,
};
}
// Convert boom response to proper format
const payload = {
error: {
code: error.output.payload.code || '',
status: error.output.payload.statusCode,
error: error.output.payload.error,
message: error.output.payload.message,
errors: error.output.payload.errors,
additionalDevelopmentData: error.output.payload.additionalDevelopmentData,
},
};
// Respond with the proper format
const format = ctx.accepts(['json', 'text']);
if (format === 'json') {
status = error.output.statusCode;
headers = error.output.headers;
body = payload;
} else if (format === 'text') {
status = error.output.statusCode;
headers = error.output.headers;
body = payload.error.message;
}
// Respond with the error
ctx.set(headers);
ctx.status = status;
ctx.body = body;
}
};
开发者ID:komapijs,项目名称:komapi,代码行数:64,代码来源:errorHandler.ts
注:本文中的Boom.notAcceptable函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论