UNPKG

@naturalcycles/nodejs-lib

Version:
36 lines (35 loc) 1.56 kB
import { AfterResponseHook, BeforeErrorHook, BeforeRequestHook, Got } from 'got'; import { GetGotOptions, GotAfterResponseHookOptions, GotBeforeRequestHookOptions, GotErrorHookOptions } from './got.model'; /** * Returns instance of Got with "reasonable defaults": * * 1. Error handler hook that prints helpful errors. * 2. Hooks that log start/end of request (optional, false by default). */ export declare function getGot(opt?: GetGotOptions): Got; /** * Without this hook (default behaviour): * * HTTPError: Response code 422 (Unprocessable Entity) * at EventEmitter.<anonymous> (.../node_modules/got/dist/source/as-promise.js:118:31) * at processTicksAndRejections (internal/process/task_queues.js:97:5) { * name: 'HTTPError' * * * With this hook: * * HTTPError 422 GET http://a.com/err?q=1 in 8 ms * { * message: 'Reference already exists', * documentation_url: 'https://developer.github.com/v3/git/refs/#create-a-reference' * } * * Features: * 1. Includes original method and URL (including e.g searchParams) in the error message. * 2. Includes response.body in the error message (limited length). * 3. Auto-detects and parses JSON response body (limited length). * 4. Includes time spent (gotBeforeRequestHook must also be enabled). */ export declare function gotErrorHook(opt?: GotErrorHookOptions): BeforeErrorHook; export declare function gotBeforeRequestHook(opt?: GotBeforeRequestHookOptions): BeforeRequestHook; export declare function gotAfterResponseHook(opt?: GotAfterResponseHookOptions): AfterResponseHook;