使用Yup的UnhandledPromiseRejectionWarning错误

时间:2019-12-23 00:16:27

标签: javascript reactjs react-native react-router yup

我收到UnhandledPromiseRejectionWarning:TypeError:Yup.string.required不是yup上_callee $错误的函数  每当我使用邮递员发送发帖请求时

import * as Yup from "yup";
import {PROVIDER_ENUM} from './customer.model';
export const create = async (req, res) => {
    const {token, provider } = req.body;

    const bodySchema = Yup.object().shape({
        token: Yup.string().required(),
        provider: Yup.string()
          .oneOf(PROVIDER_ENUM)
          .required(),
      });
    try {
        await bodySchema.validate({token, provider});
        res.status(201).json({message:'success'})
    } catch (error) {
        res.status(400).json({ message: error.message});
    }
}

这是完整的错误消息:

(node:11240) UnhandledPromiseRejectionWarning: TypeError: Yup.string.required is not a function
    at _callee$ (C:/native/lasprice/server/src/modules/customer/customer.controller.js:10:27)
    at tryCatch (C:\native\lasprice\server\node_modules\regenerator-runtime\runtime.js:65:40)
    at Generator.invoke [as _invoke] (C:\native\lasprice\server\node_modules\regenerator-runtime\runtime.js:303:22)
    at Generator.prototype.(anonymous function) [as next] (C:\native\lasprice\server\node_modules\regenerator-runtime\runtime.js:117:21)
    at step (C:\native\lasprice\server\src\modules\customer\customer.controller.js:16:191)
    at C:\native\lasprice\server\src\modules\customer\customer.controller.js:16:437
    at new Promise (<anonymous>)
    at C:\native\lasprice\server\src\modules\customer\customer.controller.js:16:99
    at create (C:/native/lasprice/server/src/modules/customer/customer.controller.js:6:14)
    at Layer.handle [as handle_request] (C:\native\lasprice\server\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\native\lasprice\server\node_modules\express\lib\router\route.js:137:13)
    at Route.dispatch (C:\native\lasprice\server\node_modules\express\lib\router\route.js:112:3)
    at Layer.handle [as handle_request] (C:\native\lasprice\server\node_modules\express\lib\router\layer.js:95:5)
    at C:\native\lasprice\server\node_modules\express\lib\router\index.js:281:22
    at Function.process_params (C:\native\lasprice\server\node_modules\express\lib\router\index.js:335:12)
    at next (C:\native\lasprice\server\node_modules\express\lib\router\index.js:275:10)
(node:11240) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:11240) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

0 个答案:

没有答案