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


TypeScript http-errors类代码示例

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


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

示例1: express

import * as util from 'util';

const app = express();

app.use((req, res, next) => {
    if (!req) {
        next(create('Please login to view this page.', 401));
        return;
    }
    next();
});

/* Examples taken from https://github.com/jshttp/http-errors/blob/1.6.2/test/test.js */

// create(status)
let err = create(404);
err; // $ExpectType HttpError
err.name; // $ExpectType string
err.message; // $ExpectType string
err.status; // $ExpectType number
err.statusCode; // $ExpectType number
err.expose; // $ExpectType boolean
err.headers; // $ExpectType { [key: string]: string; } | undefined

// create(status, msg)
err = create(404, 'LOL');

// create(status, props)
err = create(404, {id: 1});

// create(status, props) with status prop
开发者ID:PriceSpider-NeuIntel,项目名称:DefinitelyTyped,代码行数:31,代码来源:http-errors-tests.ts

示例2: return

 return (request, __, next) => {
   if (request.method === 'GET' || request.method === 'HEAD') {
     next(createError(404));
   } else {
     next(createError(501));
   }
 };
开发者ID:edhager,项目名称:intern,代码行数:7,代码来源:unhandled.ts

示例3: next

app.use((req, res, next) => {
    if (!req) {
        next(create('Please login to view this page.', 401));
        return;
    }
    next();
});
开发者ID:PriceSpider-NeuIntel,项目名称:DefinitelyTyped,代码行数:7,代码来源:http-errors-tests.ts

示例4: createError

export const compareBHash = async (value: string, hash: string): Promise<true> => {
    const isValid = await bcrypt.compare(value, hash);

    if (!isValid) {
        throw createError(401, 'No match found');
    }

    return isValid;
};
开发者ID:benjambles,项目名称:my-own-world,代码行数:9,代码来源:blowfish.ts

示例5: greet

router.get("/", (req, res, next) => {
  const name = req.query.name as string;

  if (name) {
    res.send({
      greetingMessage: greet(name)
    });
  } else {
    const err = HttpErrors(400, "Bad Request");
    next(err);
  }
});
开发者ID:AKIRA-MIYAKE,项目名称:Typeyard,代码行数:12,代码来源:index.ts

示例6: function

registerSuite('lib/middleware/finalError', function() {
  let handler: (error: any, request: any, response: any, next: any) => void;
  let request: MockRequest;
  let response: MockResponse;
  let next: SinonSpy;

  return {
    beforeEach() {
      handler = finalError();
      request = new MockRequest('GET', '/foo/bar.js');
      response = new MockResponse();
      next = spy();
    },

    tests: {
      'exposed message'() {
        const error = createError(500, 'b0rked', { expose: true });

        handler(error, request, response, next);

        assert.isFalse(next.called);
        assert.match(response.data, /500 b0rked/);
        assert.strictEqual(response.statusCode, 500);
      },

      'hidden message'() {
        const error = createError(404, 'b0rked', { expose: false });

        handler(error, request, response, next);

        assert.isFalse(next.called);
        assert.match(response.data, /404 Not Found/);
        assert.strictEqual(response.statusCode, 404);
      }
    }
  };
});
开发者ID:edhager,项目名称:intern,代码行数:37,代码来源:finalError.ts

示例7: next

        readFile(wholePath, 'utf8', (error, data) => {
          // The server was stopped in the middle of the file read
          if (context.stopped) {
            return;
          }

          if (error) {
            return next(createError(404, error, { expose: false }));
          }

          // providing `wholePath` to the instrumenter instead of a
          // partial filename is necessary because lcov.info requires
          // full path names as per the lcov spec
          data = executor.instrumentCode(data, wholePath);
          codeCache[wholePath] = {
            // strictly speaking mtime could reflect a previous
            // version, assume those race conditions are rare
            mtime,
            data
          };
          send(contentType, data);
        });
开发者ID:edhager,项目名称:intern,代码行数:22,代码来源:instrument.ts

示例8: Error

app.use(function(req: Request, res: Response, next: NextFunction) {
    let err: HttpError = Error("Not Found");
    err.status = 404;
    next(err);
});
开发者ID:phroph,项目名称:node-factorio-launcher,代码行数:5,代码来源:app.ts


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