Skip to main content

superagent

PropertyValue
Packagesuperagent
Versions Covered>=3.7.0
Contract Version1.0.0
Statusproduction
Last Verified2026-02-26
Maintainercorpus-team

Installation

npm install superagent

Covered Functions

This contract covers 7 function(s):

get()

Makes HTTP GET request

Import:

import { get } from 'superagent';

Postconditions

What happens after calling this function:

🔴 ERROR - network-error-handling

Condition: network failure, DNS error, timeout, connection refused, HTTP 4xx/5xx errors

Throws: Error with status, response, timeout fields (Promise rejection)

Required Handling:

Use try-catch (async/await) or .catch() (promises) or .end() callback

📖 Source


post()

Makes HTTP POST request

Import:

import { post } from 'superagent';

Postconditions

What happens after calling this function:

🔴 ERROR - network-error-handling

Condition: network failure, DNS error, timeout, connection refused, HTTP 4xx/5xx errors

Throws: Error with status, response, timeout fields (Promise rejection)

Required Handling:

Use try-catch (async/await) or .catch() (promises) or .end() callback

📖 Source


put()

Makes HTTP PUT request

Import:

import { put } from 'superagent';

Postconditions

What happens after calling this function:

🔴 ERROR - network-error-handling

Condition: network failure, DNS error, timeout, connection refused, HTTP 4xx/5xx errors

Throws: Error with status, response, timeout fields (Promise rejection)

Required Handling:

Use try-catch (async/await) or .catch() (promises) or .end() callback

📖 Source


patch()

Makes HTTP PATCH request

Import:

import { patch } from 'superagent';

Postconditions

What happens after calling this function:

🔴 ERROR - network-error-handling

Condition: network failure, DNS error, timeout, connection refused, HTTP 4xx/5xx errors

Throws: Error with status, response, timeout fields (Promise rejection)

Required Handling:

Use try-catch (async/await) or .catch() (promises) or .end() callback

📖 Source


delete()

Makes HTTP DELETE request

Import:

import { delete } from 'superagent';

Postconditions

What happens after calling this function:

🔴 ERROR - network-error-handling

Condition: network failure, DNS error, timeout, connection refused, HTTP 4xx/5xx errors

Throws: Error with status, response, timeout fields (Promise rejection)

Required Handling:

Use try-catch (async/await) or .catch() (promises) or .end() callback

📖 Source


del()

Makes HTTP DELETE request (IE-compatible alias)

Import:

import { del } from 'superagent';

Postconditions

What happens after calling this function:

🔴 ERROR - network-error-handling

Condition: network failure, DNS error, timeout, connection refused, HTTP 4xx/5xx errors

Throws: Error with status, response, timeout fields (Promise rejection)

Required Handling:

Use try-catch (async/await) or .catch() (promises) or .end() callback

📖 Source


Makes HTTP HEAD request

Import:

import { head } from 'superagent';

Postconditions

What happens after calling this function:

🔴 ERROR - network-error-handling

Condition: network failure, DNS error, timeout, connection refused, HTTP 4xx/5xx errors

Throws: Error with status, response, timeout fields (Promise rejection)

Required Handling:

Use try-catch (async/await) or .catch() (promises) or .end() callback

📖 Source


Example: Proper Error Handling

import superagent from 'superagent';

async function example() {
try {
const result = await get(/* args */);
// Handle success
return result;
} catch (error) {
// Handle error according to contract postconditions
console.error('Error:', error);
throw error;
}
}

See Also