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

sync-request-curl

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sync-request-curl - npm Package Compare versions

Comparing version 2.0.1 to 2.1.0

dist/cjs/errors.d.ts

2

dist/cjs/index.d.ts
import request from './request';
import { CurlError } from './errors';
export type { HttpVerb, BufferEncoding, Options, Response, SetEasyOptionCallback } from './types';
export default request;
export { CurlError };

@@ -6,6 +6,10 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.CurlError = void 0;
const request_1 = __importDefault(require("./request"));
const errors_1 = require("./errors");
Object.defineProperty(exports, "CurlError", { enumerable: true, get: function () { return errors_1.CurlError; } });
exports.default = request_1.default;
module.exports = request_1.default;
module.exports.default = request_1.default;
exports.default = request_1.default;
module.exports.CurlError = errors_1.CurlError;
//# sourceMappingURL=index.js.map

3

dist/cjs/utils.js

@@ -5,2 +5,3 @@ "use strict";

const node_libcurl_1 = require("node-libcurl");
const errors_1 = require("./errors");
const handleQs = (url, qs) => {

@@ -44,3 +45,3 @@ const urlObj = new URL(url);

if (code !== node_libcurl_1.CurlCode.CURLE_OK) {
throw new Error(`
throw new errors_1.CurlError(code, `
Curl request failed with code ${code}.

@@ -47,0 +48,0 @@ Please look up the Libcurl Error (code ${code}) here:

import request from './request';
import { CurlError } from './errors';
export type { HttpVerb, BufferEncoding, Options, Response, SetEasyOptionCallback } from './types';
export default request;
export { CurlError };
import request from './request';
import { CurlError } from './errors';
export default request;
export { CurlError };
module.exports = request;
module.exports.default = request;
export default request;
module.exports.CurlError = CurlError;
//# sourceMappingURL=index.js.map
import { CurlCode } from 'node-libcurl';
import { CurlError } from './errors';
export const handleQs = (url, qs) => {

@@ -37,3 +38,3 @@ const urlObj = new URL(url);

if (code !== CurlCode.CURLE_OK) {
throw new Error(`
throw new CurlError(code, `
Curl request failed with code ${code}.

@@ -40,0 +41,0 @@ Please look up the Libcurl Error (code ${code}) here:

@@ -7,3 +7,3 @@ {

},
"version": "2.0.1",
"version": "2.1.0",
"files": [

@@ -59,10 +59,10 @@ "dist"

"@types/morgan": "^1.9.5",
"@types/node": "^20.5.9",
"@typescript-eslint/eslint-plugin": "^6.6.0",
"@typescript-eslint/parser": "^6.6.0",
"eslint": "^8.48.0",
"@types/node": "^20.6.0",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.7.0",
"eslint": "^8.49.0",
"eslint-plugin-jest": "^27.2.3",
"express": "^4.18.2",
"http-errors": "^2.0.0",
"jest": "^29.6.4",
"jest": "^29.7.0",
"jest-dev-server": "^9.0.0",

@@ -69,0 +69,0 @@ "morgan": "^1.10.0",

@@ -78,4 +78,4 @@ <div align="center">

const res = request(
'GET',
'https://comp1531namesages.alwaysdata.net'
'GET',
'https://comp1531namesages.alwaysdata.net'
);

@@ -314,3 +314,5 @@ console.log('Status Code:', res.statusCode);

All Libcurl Errors will contain a non-zero integer code that can be looked up here:
When using the `response.getBody()` function, a generic [Error](https://nodejs.org/api/errors.html) object is thrown.
If there are issues with the request, a `CurlError` will be thrown. This will contain a non-zero `code` property that corresponds to a specific Libcurl Error from this documentation:
- https://curl.se/libcurl/c/libcurl-errors.html

@@ -330,2 +332,40 @@

It is possible to check the curl code as follows:
<details closed>
<summary>Example (click to view)</summary>
```typescript
import request, { CurlError } from 'sync-request-curl';
try {
request('GET', 'https://google.fake.url.com');
} catch (error) {
if (error instanceof CurlError) {
// outputs 6 (CURLE_COULDNT_RESOLVE_HOST)
console.log(error.code);
}
}
```
</details>
In [src/errors.ts](src/errors.ts), the `CurlError` class is defined as:
```typescript
export class CurlError extends Error {
// https://curl.se/libcurl/c/libcurl-errors.html
code: number;
constructor(code: number, message: string) {
super(message);
if (code < 1 || code > 99) {
throw new Error(`CurlError code must be between 0 and 99. Given: ${code}`);
}
this.code = code;
Object.setPrototypeOf(this, CurlError.prototype);
}
}
```
## 3. License

@@ -332,0 +372,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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