Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
resilient-fetch
Advanced tools
Readme
Resilient Fetch is a powerful utility library designed to enhance your HTTP requests by providing built-in resilience features. It's especially useful when dealing with unreliable network conditions, ensuring your applications remain robust and responsive even in challenging environments.
Key Features:
onResponse
and onError
callbacks for custom handling of responses and errors.# Using npm
npm install --save resilient-fetch
# Using yarn
yarn add resilient-fetch
import { resilientFetch } from 'resilient-fetch';
// Example 1: Fetch data with default options
const fetchDataExample1 = async () => {
try {
const { promise, cancel } = resilientFetch<string>(
'https://api.example.com/data'
);
const response = await promise;
if (response.loading) {
console.log('Loading...');
} else if (response.status === 'success') {
console.log('Success:', response.data);
console.log('Status:', response.status);
console.log('Headers:', response.headers);
} else {
console.error('Error:', response.error);
console.log('Status:', response.status);
}
// Example cancellation:
// cancel();
} catch (error) {
console.error('Catch Block Error:', error.error);
console.log('Catch Block Status:', error.status);
}
};
// Call the example function
fetchDataExample1();
// Example 2: Fetch data with custom options
const fetchDataExample2 = async () => {
try {
const { promise, cancel } = resilientFetch<string>(
'https://api.example.com/data',
{
headers: { Authorization: 'Bearer token123' },
method: 'POST',
// Add more options as needed
},
{
timeout: 15000,
retryAttempts: 3,
onResponse: async (response) => {
// Handle response interceptors if needed
},
onError: (error) => {
// Handle global error handling
console.error('Global Error Handling:', error);
},
}
);
const response = await promise;
if (response.loading) {
console.log('Loading...');
} else if (response.status === 'success') {
console.log('Success:', response.data);
console.log('Status:', response.status);
console.log('Headers:', response.headers);
} else {
console.error('Error:', response.error);
console.log('Status:', response.status);
}
// Example cancellation:
// cancel();
} catch (error) {
console.error('Catch Block Error:', error.error);
console.log('Catch Block Status:', error.status);
}
};
// Call the example function
fetchDataExample2();
resilientFetch<T>(url: string, options?: RequestInit, customOptions?: ResilientFetchOptions<T>): { promise: Promise<ResilientFetchResponse<T>>, cancel: () => void }
url
: The URL to fetch data from.options
: Optional request options (same as the standard fetch
function).customOptions
: Optional custom options for resilientFetch
: - timeout
: Timeout duration in milliseconds (default: 5000). - retryAttempts
: Number of retry attempts (default: 3). - onResponse
: Callback function to handle the response before resolving the promise. - onError
: Callback function to handle global errors.
Returns an object with a promise
that resolves to a ResilientFetchResponse<T>
and a cancel
function to abort the request.ResilientFetchResponse<T>
loading
: Boolean indicating whether the request is still loading.data
: The fetched data (nullable).status
: The status of the request ('success', 'error', or null).error
: An object containing error details (nullable).headers
: The response headers.ResilientFetchError
status
: The HTTP status code of the error.message
: The error message.This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
A resilient HTTP fetch utility
The npm package resilient-fetch receives a total of 0 weekly downloads. As such, resilient-fetch popularity was classified as not popular.
We found that resilient-fetch demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.