UnhandledPromiseRejectionWarning ошибка с использованием Yup - PullRequest
0 голосов
/ 23 декабря 2019

Я получаю UnhandledPromiseRejectionWarning: TypeError: Yup.string.required не является функцией с ошибкой _callee $ от yup всякий раз, когда я отправляю почтовый запрос с использованием почтальона

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.
...