const httpErrorB = new restifyErrors.HttpError("Hello %s!", "World");
const httpErrorC = new restifyErrors.HttpError({ statusCode: 404 }, "Hello %s!", "World");
const httpErrorD = new restifyErrors.HttpError(prevErr, "Hello World!");
const httpErrorE = new restifyErrors.HttpError(prevErr, "Hello %s!", "World");
const httpErrorF = new restifyErrors.HttpError(prevErr, { statusCode: 404 }, "Hello %s!", "World");

// RestError
const restErrorA = new restifyErrors.RestError("Hello World!");
const restErrorB = new restifyErrors.RestError("Hello %s!", "World");
const restErrorC = new restifyErrors.RestError({ statusCode: 404, restCode: "TEST" }, "Hello %s!", "World");
const restErrorD = new restifyErrors.RestError(prevErr, "Hello World!");
const restErrorE = new restifyErrors.RestError(prevErr, "Hello %s!", "World");
const restErrorF = new restifyErrors.RestError(prevErr, { statusCode: 404, restCode: "TEST" }, "Hello %s!", "World");

// Functions
restifyErrors.makeConstructor("TestError", {});
const customError = restifyErrors.makeErrFromCode(500, "Testing....");
const bunyanSerializer = restifyErrors.bunyanSerializer;

// HttpErrors
let httpError = new restifyErrors.BadRequestError();
httpError = new restifyErrors.UnauthorizedError();
httpError = new restifyErrors.PaymentRequiredError();
httpError = new restifyErrors.ForbiddenError();
httpError = new restifyErrors.NotFoundError();
httpError = new restifyErrors.MethodNotAllowedError();
httpError = new restifyErrors.NotAcceptableError();
httpError = new restifyErrors.ProxyAuthenticationRequiredError();
httpError = new restifyErrors.RequestTimeoutError();
httpError = new restifyErrors.ConflictError();
httpError = new restifyErrors.GoneError();
Example #2
0
import * as restify_errors from 'restify-errors';
import { RestError } from 'restify-errors';
import * as restify from 'restify';
import { WLError } from 'waterline';

import { IRestError } from './custom-restify-errors';

export const GenericErrorBase: IRestError = restify_errors.makeConstructor('GenericError', {
    statusCode: 400, failureType: 'GenericError'
}) as any as IRestError;

export class GenericError extends GenericErrorBase {
    constructor(generic_error: {cause?: Error, name: string, message: string, info?: {}, statusCode: number}) {
        const name = generic_error.name == null ? 'GenericError' : generic_error.name;
        super(name);
        this.code = this.displayName = this.name = name;
        this.message = `${generic_error.name}: ${generic_error.message}`;
        this.statusCode = generic_error.statusCode || 400;
        this.cause = () => generic_error.cause;
        (this as any as {info: {}}).info = this.jse_info = this.body = Object.assign({
                code: this.code, error: this.name, error_message: generic_error.message
            }, this.hasOwnProperty('_meta') && (this as any as {_meta: any})._meta ?
            { _meta: (this as any as {_meta: any})._meta } : {}
        );
        if (generic_error.info != null)
            this.jse_info = generic_error.info;
    }

    // HACK
    public toJSON() {
        return this.jse_info;