forked from request/request-promise-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
There's this new thing called inheritance
- Loading branch information
Showing
13 changed files
with
3,034 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
Oops, something went wrong.