当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Boom.badData函数代码示例

本文整理汇总了TypeScript中Boom.badData函数的典型用法代码示例。如果您正苦于以下问题:TypeScript badData函数的具体用法?TypeScript badData怎么用?TypeScript badData使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了badData函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: function

        app[config.method.toLowerCase()](config.path, async function (req: RouterRequest, res: RouterResponse, next: NextFunction) {
            // Shim the request and response objects with expected properties.
            req.domainWithProtocol = `${req.protocol}://${req.hostname}` + (req.hostname === "localhost" ? ":3000" : "");
            req.app = Object.assign({registeredRoutes}, req.app);

            if (config.bodyValidation) {
                const validation = validate(req.body, config.bodyValidation);

                if (validation.error) {
                    const error = badData(validation.error.message, validation.error.details);

                    return next(error);
                }

                req.validatedBody = validation.value;
            }

            if (config.queryValidation) {
                const validation = validate(req.query, config.queryValidation);

                if (validation.error) {
                    const error = badData(validation.error.message, validation.error.details);

                    return next(error);
                }

                req.validatedQuery = validation.value;
            }

            if (config.paramValidation) {
                const validation = validate(req.params, config.paramValidation);

                if (validation.error) {
                    const error = badData(validation.error.message, validation.error.details);

                    return next(error);
                }

                req.validatedParams = validation.value;
            }

            // Pass control to the route's handler. Handlers can be async, so wrap them in try/catch to handle promise rejections.
            try {
                const handler = config.handler(req, res, next);

                if (handler instanceof Promise) {
                    await handler;
                }

                return;
            } catch (e) {
                return next(e);
            }
        });
开发者ID:nozzlegear,项目名称:fuselage,代码行数:54,代码来源:index.ts

示例2: async

  const updateReindexStatus = async (reindexOp: ReindexSavedObject) => {
    const taskId = reindexOp.attributes.reindexTaskId;

    // Check reindexing task progress
    const taskResponse = await callCluster('tasks.get', {
      taskId,
      waitForCompletion: false,
    });

    if (!taskResponse.completed) {
      // Updated the percent complete
      const perc = taskResponse.task.status.created / taskResponse.task.status.total;
      return actions.updateReindexOp(reindexOp, {
        reindexTaskPercComplete: perc,
      });
    } else if (taskResponse.task.status.canceled === 'by user request') {
      // Set the status to cancelled
      reindexOp = await actions.updateReindexOp(reindexOp, {
        status: ReindexStatus.cancelled,
      });

      // Do any other cleanup work necessary
      reindexOp = await cleanupChanges(reindexOp);
    } else {
      // Check that it reindexed all documents
      const { count } = await callCluster('count', { index: reindexOp.attributes.indexName });

      if (taskResponse.task.status.created < count) {
        // Include the entire task result in the error message. This should be guaranteed
        // to be JSON-serializable since it just came back from Elasticsearch.
        throw Boom.badData(`Reindexing failed: ${JSON.stringify(taskResponse)}`);
      }

      // Update the status
      reindexOp = await actions.updateReindexOp(reindexOp, {
        lastCompletedStep: ReindexStep.reindexCompleted,
        reindexTaskPercComplete: 1,
      });
    }

    // Delete the task from ES .tasks index
    const deleteTaskResp = await callCluster('delete', {
      index: '.tasks',
      type: 'task',
      id: taskId,
    });

    if (deleteTaskResp.result !== 'deleted') {
      throw Boom.badImplementation(`Could not delete reindexing task ${taskId}`);
    }

    return reindexOp;
  };
开发者ID:,项目名称:,代码行数:53,代码来源:

示例3: function

        handler: async function (req, res, next) {
            const model: Requests.CreateOrUpdateAccount = req.validatedBody;

            if (await UserDb.exists(model.username.toLowerCase())) {
                return next(boom.badData(`A user with that username already exists.`));
            }

            let user = await UserDb.get(req.user._id);
            const { _id, _rev } = user;

            // Ensure the user's password is correct before changing their username
            if (!compareSync(model.password, user.hashed_password)) {
                return next(boom.forbidden(`Your password is incorrect.`));
            }

            try {
                // CouchDB does not allow modifying a doc's id, so we copy the user to a new document instead.
                const copyResult = await UserDb.copy(_id, model.username.toLowerCase());
                const user = await UserDb.get(copyResult.id);
            } catch (e) {
                inspect("Failed to copy user model to new id.", e);

                return next(boom.badData("Failed to save new user id."));
            }

            try {
                // Delete the old user document
                await UserDb.delete(_id, _rev);
            } catch (e) {
                inspect(`Failed to delete user doc ${_id} after changing username to ${model.username}`, e);
            }

            await res.withSessionToken(user);

            return next();
        }
开发者ID:nozzlegear,项目名称:Gearworks,代码行数:36,代码来源:users.ts

示例4: updateAppConfig

export async function updateAppConfig(server: Server, request: Request, reply: IReply)
{
    const validation = joi.validate<DeliverSettings>(request.payload, Validation.UpdateAppConfig)

    if (validation.error)
    {
        return reply(Boom.badData(humanizeError(validation.error), validation.error));
    }

    const payload = validation.value;
    let user: User;

    try 
    {
        user = await Users.get<User>(request.auth.credentials.userId);
    }
    catch (e)
    {
        console.error("Failed to retrieve user from database.", e);

        return reply(Boom.wrap(e));
    }

    user.appConfig = payload;

    const update = await Users.put(user);

    if (!update.ok)
    {   
        console.error("Failed to update user's app config.", update);

        return reply(Boom.expectationFailed("Failed to update user's app config."));
    }

    // Bust the cache so users on the shop see this change immediately.
    await setCacheValue(Caches.shopTagConfig, user.shopifyShopId.toString(), user.appConfig);

    return reply.continue() as any;
}
开发者ID:nozzlegear,项目名称:deliver-on,代码行数:39,代码来源:api-v1-routes.ts

示例5: reply

 .catch((errors) => {
     let error = boom.badData();
     error.reformat();
     error.output.payload.errors = errors;
     reply(error);
 });
开发者ID:csgpro,项目名称:csgpro.com,代码行数:6,代码来源:contact.controller.ts

示例6: switch

    // assignment is possible due to default generic Data = any
    const customError: Boom.BoomError<CustomData> = err;

    // Discriminated union type works:
    switch (customError.data.customType) {
        case 'Custom1':
            customError.data.custom1;
            break;
        case 'Custom2':
            customError.data.custom2;
            break;
    }
};

// Accepts a simple Boom error
handleError(Boom.badData());

// Accepts an error with custom data
const errorWithData = Boom.badImplementation('', { custom1: 'test', customType: 'Custom1' as 'Custom1', isCustom: true as true });
handleError(errorWithData);

// Accepts an error with a more explicit type
const errorWithExplicitType: Boom.BoomError<CustomData> = errorWithData;
handleError(errorWithExplicitType);

// Accepts an error with an even more explicit type
const errorWithConcreteCustomData: Boom.BoomError<CustomData1> = errorWithData; // assignment to CustomData2 would not be possible
handleError(errorWithConcreteCustomData);

/**
 * Some complex error data types:
开发者ID:CNBoland,项目名称:DefinitelyTyped,代码行数:31,代码来源:errors.ts


注:本文中的Boom.badData函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。