/// /// /// /** * Provides the core features of a Crea application. */ import * as KoaApplication from 'koa'; import { IncomingForm } from 'formidable'; import { ResponderConstructor } from './responder'; /** An error in an application. */ export declare class ApplicationError extends Error { /** The HTTP status code of the error, to be sent in response. */ status: number; /** * Any error data to be sent in response. * It is completely up to the instantiater as to what * to populate here - it */ data?: any; /** * Construct an application error. * * @param status The HTTP status code. * @param message The error message. * @param data The error data. */ constructor(status: number, message: string, data?: any); /** * All of the registered handlers for coercing non-`ApplicationErrors` into * their relevant `ApplicationError` form. */ static handlers: Map ApplicationError>; /** * Coerce any error type into an `ApplicationError`. * * This will lookup the registered coercion handlers based off the error provided. * If no coerce handler has been provided, then th * * By default the following coercion handlers are enabled: * * * modelsafe.ValidationError: 400 Bad Request, with the `data` field populated with the errors for each request field * * restla.TokenExpiryError: 401 Unauthorised * * restla.TokenInvalidError: 401 Unauthorised * * restla.UserNotFoundError: 401 Unauthorised * * restla.AuthorisationError: 403 Forbidden */ static coerce(err: Error | ApplicationError): ApplicationError; /** * Register a handler for coercing another error type * into an application error. * * This is useful if you ever intend to throw non-`ApplicationError`s * anywhere in your code - Restla will automatically catch those * and then look for a coerce handler for that error. If no handler * has been registered, then it will just coerc into a generic 500 status * `ApplicationError` with the error message carried across. * * @see coerce * @param ctor The error constructor to automatically coerce using the handler. * @param handler The handler that turns the relevant error type into an application error. */ static register(ctor: Function, handler: (err: T) => ApplicationError): void; } /** Options for running an application. */ export interface ApplicationOptions { /** The responder class to use for sending REST responses to clients. */ responder: ResponderConstructor; /** * Whether multipart requests should be parsed. Off by default to prevent overhead * in apps that don't need file uploads or other multipart requests. * * If a set of formidable options are provided instead of a boolean, * then they will be used as the options for parsing multipart with formidable. */ multipart: boolean | Partial; } /** * The web application. * * This is functionally equivalent to a Koa application, * except we use some must-have/good-to-have middlewares * early on and provide some extra things, such as smart error handling. */ export declare class Application extends KoaApplication { /** The options for the application. */ protected options: ApplicationOptions; /** * Construct an application. * * @param options Any options for the application. */ constructor(options?: Partial); }