1

嗨,当我尝试使用 Lab 模块在 Node 中使用 Hapijs 编写我的 API 时,我遇到了这个错误:

首选项为 make 返回 200 HTTP 代码:

  getaddrinfo ENOTFOUND undefined

  at errnoException (dns.js:44:10)
  at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:94:26)

测试目录中的文件 index.js 是这样的:

'use strict';

var Lab = require('lab');

var Code = require('code');
var Hapi = require('hapi');
var Joi = require('joi');

// internal object
var internals = {};

// Test shortcuts
var lab = exports.lab = Lab.script();
var experiment = lab.experiment;
var describe = lab.describe;
var it = lab.it;
var before = lab.before;
var expect = Code.expect;

describe('Preferences', function() {

it("return 200 HTTP code wfor the make", function(done) {

  var server = new Hapi.Server();
  server.connection();
  server.route({
      method: 'GET',
      path: '/makes',
      config: {
          handler: require('../handlers/cars').getMakes,
          validate: {

          }
      }
  });

  server.inject({
      method: 'GET',
      url: '/makes',

  }, function(res) {
      expect(res.statusCode).to.equal(200);
      done();
  });
 });
 });

文件 route.js 是这样的:

module.exports = [{
path: '/makes',
method: 'GET',
config: {
//auth: 'session', only for testing disable the auth
auth: 'false',
handler: cars.getMakes
}

我已禁用此测试的身份验证,处理程序是这样的:

getMakes: function (request, reply) {
Make
  .find()
  .sort('name')
  .exec( function(err, result) {

      if (err) {
         request.log(['server', 'database', 'error'], 'An error occured during the execution of the query');
     }

     return reply(result)
        .code(200);
    });

},你能解释一下错误在哪里以及为什么它会显示这种错误类型吗?

4

0 回答 0