mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Merge pull request #7267 from tkrotoff/HttpError
Export interfaces for api-error-handler and http-errors
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/// <reference path="api-error-handler.d.ts" />
|
||||
|
||||
import errorHandler = require('api-error-handler');
|
||||
import express = require('express');
|
||||
import * as errorHandler from 'api-error-handler';
|
||||
import * as express from 'express';
|
||||
|
||||
var api = express.Router();
|
||||
api.get('/users/:userid', function (req, res, next) {
|
||||
@@ -9,3 +9,5 @@ api.get('/users/:userid', function (req, res, next) {
|
||||
});
|
||||
|
||||
api.use(errorHandler());
|
||||
|
||||
let res: errorHandler.Response;
|
||||
|
||||
+17
-1
@@ -6,7 +6,23 @@
|
||||
/// <reference path="../express/express.d.ts" />
|
||||
|
||||
declare module 'api-error-handler' {
|
||||
import express = require('express');
|
||||
import * as express from 'express';
|
||||
|
||||
namespace apiErrorHandler {
|
||||
|
||||
// Body response: the JSON returned by api-error-handler
|
||||
// See https://github.com/expressjs/api-error-handler/blob/1.0.0/index.js
|
||||
interface Response {
|
||||
status: number;
|
||||
stack?: string;
|
||||
message: string;
|
||||
|
||||
// Client errors
|
||||
code?: any;
|
||||
name?: string;
|
||||
type?: any;
|
||||
}
|
||||
}
|
||||
|
||||
function apiErrorHandler(options?: any): express.ErrorRequestHandler;
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
/// <reference path="errorhandler.d.ts" />
|
||||
|
||||
import express = require('express');
|
||||
import errorhandler = require('errorhandler');
|
||||
import * as express from 'express';
|
||||
import * as errorhandler from 'errorhandler';
|
||||
|
||||
var app = express();
|
||||
|
||||
app.use(errorhandler());
|
||||
@@ -14,4 +15,4 @@ app.use(errorhandler({ log: (err, str, req, res) => {
|
||||
|
||||
const requestWasFresh = req && req.fresh;
|
||||
const responseContentType = res && res.contentType
|
||||
}}))
|
||||
}}))
|
||||
|
||||
Vendored
+6
-6
@@ -6,19 +6,19 @@
|
||||
/// <reference path="../express/express.d.ts" />
|
||||
|
||||
declare module "errorhandler" {
|
||||
import express = require('express');
|
||||
|
||||
import * as express from 'express';
|
||||
|
||||
function errorHandler(options?: errorHandler.Options): express.ErrorRequestHandler;
|
||||
|
||||
|
||||
namespace errorHandler {
|
||||
interface LoggingCallback {
|
||||
(err: Error, str: string, req: express.Request, res: express.Response): void;
|
||||
}
|
||||
|
||||
|
||||
interface Options {
|
||||
/**
|
||||
* Defaults to true.
|
||||
*
|
||||
*
|
||||
* Possible values:
|
||||
* true : Log errors using console.error(str).
|
||||
* false : Only send the error back in the response.
|
||||
@@ -27,6 +27,6 @@ declare module "errorhandler" {
|
||||
log: boolean | LoggingCallback;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export = errorHandler;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/// <reference path="http-errors.d.ts" />
|
||||
/// <reference path="../express/express.d.ts" />
|
||||
|
||||
import createError = require('http-errors');
|
||||
import express = require('express');
|
||||
import * as createError from 'http-errors';
|
||||
import * as express from 'express';
|
||||
|
||||
var app = express();
|
||||
|
||||
@@ -67,3 +67,5 @@ var err = new createError['404']();
|
||||
|
||||
//createError['404'](); // TypeScript should fail with "Did you mean to include 'new'?"
|
||||
//new createError(); // TypeScript should fail with "Only a void function can be called with the 'new' keyword"
|
||||
|
||||
let error: createError.HttpError;
|
||||
|
||||
Vendored
+80
-76
@@ -4,82 +4,86 @@
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module 'http-errors' {
|
||||
interface HttpError extends Error {
|
||||
status: number;
|
||||
statusCode: number;
|
||||
expose: boolean;
|
||||
namespace createHttpError {
|
||||
|
||||
// See https://github.com/jshttp/http-errors/blob/1.3.1/index.js#L42
|
||||
interface HttpError extends Error {
|
||||
status: number;
|
||||
statusCode: number;
|
||||
expose: boolean;
|
||||
}
|
||||
|
||||
interface CreateHttpError {
|
||||
// See https://github.com/Microsoft/TypeScript/issues/227#issuecomment-50092674
|
||||
[code: string]: new() => HttpError;
|
||||
|
||||
(...args: Array<Error | string | number | Object>): HttpError;
|
||||
|
||||
Continue: new() => HttpError;
|
||||
SwitchingProtocols: new() => HttpError;
|
||||
Processing: new() => HttpError;
|
||||
OK: new() => HttpError;
|
||||
Created: new() => HttpError;
|
||||
Accepted: new() => HttpError;
|
||||
NonAuthoritativeInformation: new() => HttpError;
|
||||
NoContent: new() => HttpError;
|
||||
ResetContent: new() => HttpError;
|
||||
PartialContent: new() => HttpError;
|
||||
MultiStatus: new() => HttpError;
|
||||
AlreadyReported: new() => HttpError;
|
||||
IMUsed: new() => HttpError;
|
||||
MultipleChoices: new() => HttpError;
|
||||
MovedPermanently: new() => HttpError;
|
||||
Found: new() => HttpError;
|
||||
SeeOther: new() => HttpError;
|
||||
NotModified: new() => HttpError;
|
||||
UseProxy: new() => HttpError;
|
||||
Unused: new() => HttpError;
|
||||
TemporaryRedirect: new() => HttpError;
|
||||
PermanentRedirect: new() => HttpError;
|
||||
BadRequest: new() => HttpError;
|
||||
Unauthorized: new() => HttpError;
|
||||
PaymentRequired: new() => HttpError;
|
||||
Forbidden: new() => HttpError;
|
||||
NotFound: new() => HttpError;
|
||||
MethodNotAllowed: new() => HttpError;
|
||||
NotAcceptable: new() => HttpError;
|
||||
ProxyAuthenticationRequired: new() => HttpError;
|
||||
RequestTimeout: new() => HttpError;
|
||||
Conflict: new() => HttpError;
|
||||
Gone: new() => HttpError;
|
||||
LengthRequired: new() => HttpError;
|
||||
PreconditionFailed: new() => HttpError;
|
||||
PayloadTooLarge: new() => HttpError;
|
||||
URITooLong: new() => HttpError;
|
||||
UnsupportedMediaType: new() => HttpError;
|
||||
RangeNotSatisfiable: new() => HttpError;
|
||||
ExpectationFailed: new() => HttpError;
|
||||
ImATeapot: new() => HttpError;
|
||||
UnprocessableEntity: new() => HttpError;
|
||||
Locked: new() => HttpError;
|
||||
FailedDependency: new() => HttpError;
|
||||
UnorderedCollection: new() => HttpError;
|
||||
UpgradeRequired: new() => HttpError;
|
||||
PreconditionRequired: new() => HttpError;
|
||||
TooManyRequests: new() => HttpError;
|
||||
RequestHeaderFieldsTooLarge: new() => HttpError;
|
||||
UnavailableForLegalReasons: new() => HttpError;
|
||||
InternalServerError: new() => HttpError;
|
||||
NotImplemented: new() => HttpError;
|
||||
BadGateway: new() => HttpError;
|
||||
ServiceUnavailable: new() => HttpError;
|
||||
GatewayTimeout: new() => HttpError;
|
||||
HTTPVersionNotSupported: new() => HttpError;
|
||||
VariantAlsoNegotiates: new() => HttpError;
|
||||
InsufficientStorage: new() => HttpError;
|
||||
LoopDetected: new() => HttpError;
|
||||
BandwidthLimitExceeded: new() => HttpError;
|
||||
NotExtended: new() => HttpError;
|
||||
NetworkAuthenticationRequired: new() => HttpError;
|
||||
}
|
||||
}
|
||||
|
||||
interface CreateHttpError {
|
||||
// See https://github.com/Microsoft/TypeScript/issues/227#issuecomment-50092674
|
||||
[code: string]: new() => HttpError;
|
||||
|
||||
(...args: Array<Error | string | number | Object>): HttpError;
|
||||
|
||||
Continue: new() => HttpError;
|
||||
SwitchingProtocols: new() => HttpError;
|
||||
Processing: new() => HttpError;
|
||||
OK: new() => HttpError;
|
||||
Created: new() => HttpError;
|
||||
Accepted: new() => HttpError;
|
||||
NonAuthoritativeInformation: new() => HttpError;
|
||||
NoContent: new() => HttpError;
|
||||
ResetContent: new() => HttpError;
|
||||
PartialContent: new() => HttpError;
|
||||
MultiStatus: new() => HttpError;
|
||||
AlreadyReported: new() => HttpError;
|
||||
IMUsed: new() => HttpError;
|
||||
MultipleChoices: new() => HttpError;
|
||||
MovedPermanently: new() => HttpError;
|
||||
Found: new() => HttpError;
|
||||
SeeOther: new() => HttpError;
|
||||
NotModified: new() => HttpError;
|
||||
UseProxy: new() => HttpError;
|
||||
Unused: new() => HttpError;
|
||||
TemporaryRedirect: new() => HttpError;
|
||||
PermanentRedirect: new() => HttpError;
|
||||
BadRequest: new() => HttpError;
|
||||
Unauthorized: new() => HttpError;
|
||||
PaymentRequired: new() => HttpError;
|
||||
Forbidden: new() => HttpError;
|
||||
NotFound: new() => HttpError;
|
||||
MethodNotAllowed: new() => HttpError;
|
||||
NotAcceptable: new() => HttpError;
|
||||
ProxyAuthenticationRequired: new() => HttpError;
|
||||
RequestTimeout: new() => HttpError;
|
||||
Conflict: new() => HttpError;
|
||||
Gone: new() => HttpError;
|
||||
LengthRequired: new() => HttpError;
|
||||
PreconditionFailed: new() => HttpError;
|
||||
PayloadTooLarge: new() => HttpError;
|
||||
URITooLong: new() => HttpError;
|
||||
UnsupportedMediaType: new() => HttpError;
|
||||
RangeNotSatisfiable: new() => HttpError;
|
||||
ExpectationFailed: new() => HttpError;
|
||||
ImATeapot: new() => HttpError;
|
||||
UnprocessableEntity: new() => HttpError;
|
||||
Locked: new() => HttpError;
|
||||
FailedDependency: new() => HttpError;
|
||||
UnorderedCollection: new() => HttpError;
|
||||
UpgradeRequired: new() => HttpError;
|
||||
PreconditionRequired: new() => HttpError;
|
||||
TooManyRequests: new() => HttpError;
|
||||
RequestHeaderFieldsTooLarge: new() => HttpError;
|
||||
UnavailableForLegalReasons: new() => HttpError;
|
||||
InternalServerError: new() => HttpError;
|
||||
NotImplemented: new() => HttpError;
|
||||
BadGateway: new() => HttpError;
|
||||
ServiceUnavailable: new() => HttpError;
|
||||
GatewayTimeout: new() => HttpError;
|
||||
HTTPVersionNotSupported: new() => HttpError;
|
||||
VariantAlsoNegotiates: new() => HttpError;
|
||||
InsufficientStorage: new() => HttpError;
|
||||
LoopDetected: new() => HttpError;
|
||||
BandwidthLimitExceeded: new() => HttpError;
|
||||
NotExtended: new() => HttpError;
|
||||
NetworkAuthenticationRequired: new() => HttpError;
|
||||
}
|
||||
|
||||
var httpError: CreateHttpError;
|
||||
export = httpError;
|
||||
var createHttpError: createHttpError.CreateHttpError;
|
||||
export = createHttpError;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user