Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typed-rest-client

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typed-rest-client - npm Package Compare versions

Comparing version 0.14.1 to 0.14.2

12

package.json
{
"name": "typed-rest-client",
"version": "0.14.1",
"version": "0.14.2",
"description": "Node Rest and Http Clients for use with TypeScript",

@@ -29,9 +29,9 @@ "main": "./RestClient.js",

"devDependencies": {
"typescript": "2.4.2",
"@types/mocha": "^2.2.44",
"@types/node": "^8.0.19",
"@types/shelljs": "0.7.4",
"mocha": "^3.5.3",
"node": "^8.0.19",
"@types/node": "^8.0.19",
"shelljs": "0.7.6",
"@types/shelljs": "0.7.4",
"mocha": "^3.2.0",
"@types/mocha": "^2.2.41"
"typescript": "2.4.2"
},

@@ -38,0 +38,0 @@ "dependencies": {

@@ -30,2 +30,22 @@ # Typed Rest and Http Client with TypeScript Typings

Also see [rest](./test/resttests.ts) and [http](./test/httptests.ts) tests for detailed examples.
## Errors
### http
The http client does not throw unless truly exceptional. A request that successfully executes resulting in a 404, 500 etc... will return a response object with a status code and a body. Redirects (3xx) will be followed by default.
See [http tests](./test/httptests.ts) for detailed examples.
### rest
The rest client is a high level client which uses the http client. It's responsibility is to turn a body into a typed resource object.
A 200 will be success.
Redirects (3xx) will be followed.
A 404 will not throw but the result object will be null and the result statusCode will be set.
Other 4xx and 5xx errors will throw. The status code will be attached to the error object. If a restful error object is returned ({ message: xxx}), then the error message will be that. Otherwise, it will be a generic, "Failed Request: (xxx)".
See [rest tests](./test/resttests.ts) for detailed examples.
## Contributing

@@ -32,0 +52,0 @@

@@ -125,6 +125,2 @@ "use strict";

}
// should move to the consumer
// public createAcceptHeader(type: string, apiVersion?: string): string {
// return type + (apiVersion ? (';' + this.versionParam + '=' + apiVersion) : '');
// }
_headersFromOptions(options, contentType) {

@@ -164,4 +160,5 @@ options = options || {};

catch (err) {
reject(new Error('Invalid Resource'));
// Invalid resource (contents not json); leaving result obj null
}
// note that 3xx redirects are handled by the http layer.
if (statusCode > 299) {

@@ -174,5 +171,11 @@ let msg;

else {
msg = "Failed request: (" + statusCode + ") " + res.message.url;
msg = "Failed request: (" + statusCode + ")";
}
reject(new Error(msg));
let err = new Error(msg);
// attach statusCode and body obj (if available) to the error object
err['statusCode'] = statusCode;
if (rres.result) {
err['result'] = rres.result;
}
reject(err);
}

@@ -179,0 +182,0 @@ else {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc