节点JS self._callback.apply不是函数错误

时间:2018-11-12 08:45:09

标签: javascript node.js typescript callback

    import axios from 'axios';
import * as jwt from 'jsonwebtoken';
import { Action } from 'routing-controllers';
import { Connection } from 'typeorm';

import { env } from '../env';

export function authorizationChecker( connection: Connection): (action: Action, roles: any[]) => Promise<boolean> | boolean {
    let validationKey: any = axios.get(env.auth.jwksUri).then(response => {
        validationKey = response.data.keys[0].value;
    }).catch();
    return async function innerAuthorizationChecker(
        action: Action,
        roles: string[]
    ): Promise<boolean> {
        // here you can use request/response objects from action
        // also if decorator defines roles it needs to access the actio
        // you can use them to provide granular access check
        // checker must return either boolean (true or false)
        // either promise that resolves a boolean value
        try {
            const token = (action.request.headers.token || 
               action.request.headers.authorization).replace('Bearer ', '');
            await jwt.verify(token, validationKey);
            return true;
        } catch (e) {
            return false;
        }
    };
}

这是我的错误:

错误:[app]应用程序崩溃:类型错误:self._callback.apply不是函数 (节点:512)UnhandledPromiseRejectionWarning:未处理的承诺拒绝(拒绝ID:1):TypeError:无法读取未定义的属性“ 0” (节点:512)[DEP0018] DeprecationWarning:已弃用未处理的承诺拒绝。将来,未处理的承诺拒绝将终止Node.js 使用非零退出代码进行处理。

我正在尝试从服务的特定URL获取验证密钥集,但是以某种方式(未调用该函数)它表示响应数据未定义。最重要的是,我遇到了这个错误:self._callback.apply不是一个函数。

以前有人处理过此类回调错误吗?在stackoverflow上找不到与我的问题有关的任何内容。

0 个答案:

没有答案