Skip to content

Commit

Permalink
There's this new thing called inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
jgoz committed Nov 19, 2023
1 parent 578970f commit 264b469
Show file tree
Hide file tree
Showing 13 changed files with 3,034 additions and 288 deletions.
26 changes: 17 additions & 9 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"root": true,
"parser": "espree",
"parserOptions": {
"ecmaVersion": 5,
"ecmaVersion": 6,
"sourceType": "script",
"ecmaFeatures": {}
},
Expand All @@ -14,7 +14,6 @@
"Promise": false
},
"rules": {

// Possible Errors (fully reviewed 2016-07-05)

"no-cond-assign": 2,
Expand Down Expand Up @@ -103,14 +102,17 @@
"no-undef": [2, { "typeof": true }],
"no-undef-init": 2,
"no-undefined": 0,
"no-unused-vars": [2, { "vars": "local", "args": "none", "caughtErrors": "none" }],
"no-unused-vars": [
2,
{ "vars": "local", "args": "none", "caughtErrors": "none" }
],
"no-use-before-define": [2, { "functions": false, "classes": true }],

// Node.js and CommonJS (fully reviewed 2016-07-05)

"callback-return": 0,
"global-require": 0,
"handle-callback-err": [2, "^(err|error)$" ],
"handle-callback-err": [2, "^(err|error)$"],
"no-mixed-requires": 0,
"no-new-require": 2,
"no-path-concat": 2,
Expand All @@ -124,7 +126,7 @@
"block-spacing": 2,
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
"camelcase": [2, { "properties": "never" }],
"comma-dangle": [2, "never"],
"comma-dangle": [2, "always"],
"comma-spacing": 2,
"comma-style": 2,
"eol-last": 2,
Expand All @@ -144,17 +146,23 @@
"no-unneeded-ternary": [2, { "defaultAssignment": false }],
"no-whitespace-before-property": 2,
"one-var": 0,
"operator-linebreak": [2, "after", { "overrides": { "?": "before", ":": "before" } }],
"operator-linebreak": [
2,
"after",
{ "overrides": { "?": "before", ":": "before" } }
],
"padded-blocks": 0,
"quotes": [2, "single", "avoid-escape"],
"quotes": [2, "double", "avoid-escape"],
"semi": [2, "always"],
"semi-spacing": 2,
"space-before-blocks": 2,
"space-before-function-paren": [2, {"anonymous": "always", "named": "never"}],
"space-before-function-paren": [
2,
{ "anonymous": "always", "named": "never" }
],
"space-in-parens": 0,
"space-infix-ops": 0,
"space-unary-ops": 2,
"spaced-comment": 0

}
}
58 changes: 58 additions & 0 deletions errors.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import rp from "./index";

export interface RequestError extends Error {
cause: any;
error: any;
options: rp.Options;
response: rp.FullResponse;
}
export interface RequestErrorConstructor {
new (
cause: any,
options: rp.Options,
response: rp.FullResponse
): RequestError;
(cause: any, options: rp.Options, response: rp.FullResponse): RequestError;
prototype: RequestError;
}
export const RequestError: RequestErrorConstructor;

export interface StatusCodeError extends Error {
statusCode: number;
error: any;
options: rp.Options;
response: rp.FullResponse;
}
export interface StatusCodeErrorConstructor extends Error {
new (
statusCode: number,
body: any,
options: rp.Options,
response: rp.FullResponse
): StatusCodeError;
(
statusCode: number,
body: any,
options: rp.Options,
response: rp.FullResponse
): StatusCodeError;
prototype: StatusCodeError;
}
export const StatusCodeError: StatusCodeErrorConstructor;

export interface TransformError extends Error {
cause: any;
error: any;
options: rp.Options;
response: rp.FullResponse;
}
export interface TransformErrorConstructor extends Error {
new (
cause: any,
options: rp.Options,
response: rp.FullResponse
): TransformError;
(cause: any, options: rp.Options, response: rp.FullResponse): TransformError;
prototype: TransformError;
}
export const TransformError: TransformErrorConstructor;
4 changes: 2 additions & 2 deletions errors.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
'use strict';
"use strict";

module.exports = require('request-promise-core/errors');
module.exports = require("./lib/errors");
121 changes: 0 additions & 121 deletions gulpfile.js

This file was deleted.

31 changes: 31 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import request from "@implydata/request";

declare namespace requestPromise {
interface RequestPromise<T = any> extends request.Request, Promise<T> {
promise(): Promise<T>;
}

interface RequestPromiseOptions extends request.CoreOptions {
simple?: boolean | undefined;
transform?(
body: any,
response: request.Response,
resolveWithFullResponse?: boolean
): any;
transform2xxOnly?: boolean | undefined;
resolveWithFullResponse?: boolean | undefined;
}

type RequestPromiseAPI = request.RequestAPI<
RequestPromise,
RequestPromiseOptions,
request.RequiredUriUrl
>;
type FullResponse = request.Response;
type OptionsWithUri = request.UriOptions & RequestPromiseOptions;
type OptionsWithUrl = request.UrlOptions & RequestPromiseOptions;
type Options = OptionsWithUri | OptionsWithUrl;
}

declare const requestPromise: requestPromise.RequestPromiseAPI;
export = requestPromise;
58 changes: 58 additions & 0 deletions lib/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"use strict";

function RequestError(cause, options, response) {
this.name = "RequestError";
this.message = String(cause);
this.cause = cause;
this.error = cause; // legacy attribute
this.options = options;
this.response = response;

if (Error.captureStackTrace) {
// required for non-V8 environments
Error.captureStackTrace(this);
}
}
RequestError.prototype = Object.create(Error.prototype);
RequestError.prototype.constructor = RequestError;

function StatusCodeError(statusCode, body, options, response) {
this.name = "StatusCodeError";
this.statusCode = statusCode;
this.message =
statusCode +
" - " +
(JSON && JSON.stringify ? JSON.stringify(body) : body);
this.error = body; // legacy attribute
this.options = options;
this.response = response;

if (Error.captureStackTrace) {
// required for non-V8 environments
Error.captureStackTrace(this);
}
}
StatusCodeError.prototype = Object.create(Error.prototype);
StatusCodeError.prototype.constructor = StatusCodeError;

function TransformError(cause, options, response) {
this.name = "TransformError";
this.message = String(cause);
this.cause = cause;
this.error = cause; // legacy attribute
this.options = options;
this.response = response;

if (Error.captureStackTrace) {
// required for non-V8 environments
Error.captureStackTrace(this);
}
}
TransformError.prototype = Object.create(Error.prototype);
TransformError.prototype.constructor = TransformError;

module.exports = {
RequestError: RequestError,
StatusCodeError: StatusCodeError,
TransformError: TransformError,
};
Loading

0 comments on commit 264b469

Please sign in to comment.