This commit is contained in:
Bret Comnes 2020-02-10 13:21:06 -07:00
parent 071806b04f
commit 720ecbfa14
No known key found for this signature in database
GPG Key ID: 3705F4634DC3A1AC
9 changed files with 80 additions and 76 deletions

View File

@ -1,26 +1,26 @@
{
"_from": "async-neocities-tmp@0.0.2",
"_id": "async-neocities-tmp@0.0.2",
"_from": "async-neocities-tmp@^0.0.4",
"_id": "async-neocities-tmp@0.0.4",
"_inBundle": false,
"_integrity": "sha512-MP8zp6gdM92e9cODhDtBHu9n6XwiwlIG1/rgqalTu3wYdfTNwJtzXKNUWvdy934R+oeLk6mfGywQGM4YdnHHnw==",
"_integrity": "sha512-sJMy3T04IDDxAVBZkqGcGy9NjFMW/rdCA8LC7tCgWYQA6/cGhjrnB85EVcjNWqjekEuogSTwrurblp7ZQxU5ww==",
"_location": "/async-neocities-tmp",
"_phantomChildren": {},
"_requested": {
"type": "version",
"type": "range",
"registry": true,
"raw": "async-neocities-tmp@0.0.2",
"raw": "async-neocities-tmp@^0.0.4",
"name": "async-neocities-tmp",
"escapedName": "async-neocities-tmp",
"rawSpec": "0.0.2",
"rawSpec": "^0.0.4",
"saveSpec": null,
"fetchSpec": "0.0.2"
"fetchSpec": "^0.0.4"
},
"_requiredBy": [
"/"
],
"_resolved": "https://registry.npmjs.org/async-neocities-tmp/-/async-neocities-tmp-0.0.2.tgz",
"_shasum": "b7cf75f9c61700e512d670143f4ab9c1b0b34f0d",
"_spec": "async-neocities-tmp@0.0.2",
"_resolved": "https://registry.npmjs.org/async-neocities-tmp/-/async-neocities-tmp-0.0.4.tgz",
"_shasum": "f0a2075db8899d149ccf3b8c2fc1893505e7ef3f",
"_spec": "async-neocities-tmp@^0.0.4",
"_where": "/Users/bret/repos/deploy-to-neocities",
"author": {
"name": "Bret Comnes",
@ -33,7 +33,7 @@
"bundleDependencies": false,
"dependencies": {
"async-folder-walker": "^2.0.1",
"fetch-errors": "^1.0.1",
"fetch-errors": "^2.0.1",
"form-data": "^3.0.0",
"nanoassert": "^2.0.0",
"node-fetch": "^2.6.0",
@ -68,5 +68,5 @@
"dist"
]
},
"version": "0.0.2"
"version": "0.0.4"
}

View File

@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
node-version: [8.x, 10.x, 12.x]
node-version: [12.x]
steps:
- uses: actions/checkout@v1

View File

@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
## 2.0.0 - 2020-02-10
* Remove esm, export CJS. ESM doesn't provide any advantage in Node.js modueles.
## 1.0.1 - 2019-11-19
* Add missing devdep.

View File

@ -1,6 +1,5 @@
# fetch-errors
[![Actions Status](https://github.com/bcomnes/fetch-errors/workflows/tests/badge.svg)](https://github.com/bcomnes/fetch-errors/actions)
[![Exports](https://img.shields.io/badge/exports-esm-blue)](https://github.com/standard-things/esm)
Error subclasses for Text and JSON `fetch` response bodies, and a `handleResponse` fuction to handle fetch responses cleanly.
@ -11,12 +10,12 @@ npm install fetch-errors
## Usage
``` js
import {
const {
HTTPError,
TextHTTPError,
JSONHTTPError,
handleResponse
} from 'fetch-errors';
} = require('fetch-errors');
window.fetch('https://api.github.com/users/bcomnes/repos')
.then(handleResponse)

49
node_modules/fetch-errors/index.js generated vendored
View File

@ -1,4 +1,45 @@
// Set options as a parameter, environment variable, or rc file.
// eslint-disable-next-line no-global-assign
require = require('esm')(module/* , options */);
module.exports = require('./main.js');
async function handleResponse (response) {
const contentType = response.headers.get('Content-Type');
const isJSON = contentType && contentType.match(/json/);
const data = isJSON ? await response.json() : await response.text();
if (response.ok) return data;
else {
return isJSON
? Promise.reject(new JSONHTTPError(response, data))
: Promise.reject(new TextHTTPError(response, data));
}
}
class HTTPError extends Error {
constructor (response) {
super(response.statusText);
this.name = this.constructor.name;
if (typeof Error.captureStackTrace === 'function') {
Error.captureStackTrace(this, this.constructor);
} else {
this.stack = new Error(response.statusText).stack;
}
this.status = response.status;
}
}
class TextHTTPError extends HTTPError {
constructor (response, data) {
super(response);
this.data = data;
}
}
class JSONHTTPError extends HTTPError {
constructor (response, json) {
super(response);
this.json = json;
}
}
module.exports = {
handleResponse,
HTTPError,
TextHTTPError,
JSONHTTPError
};

38
node_modules/fetch-errors/main.js generated vendored
View File

@ -1,38 +0,0 @@
export async function handleResponse (response) {
const contentType = response.headers.get('Content-Type');
const isJSON = contentType && contentType.match(/json/);
const data = isJSON ? await response.json() : await response.text();
if (response.ok) return data;
else {
return isJSON
? Promise.reject(new JSONHTTPError(response, data))
: Promise.reject(new TextHTTPError(response, data));
}
}
export class HTTPError extends Error {
constructor (response) {
super(response.statusText);
this.name = this.constructor.name;
if (typeof Error.captureStackTrace === 'function') {
Error.captureStackTrace(this, this.constructor);
} else {
this.stack = new Error(response.statusText).stack;
}
this.status = response.status;
}
}
export class TextHTTPError extends HTTPError {
constructor (response, data) {
super(response);
this.data = data;
}
}
export class JSONHTTPError extends HTTPError {
constructor (response, json) {
super(response);
this.json = json;
}
}

View File

@ -1,26 +1,26 @@
{
"_from": "fetch-errors@^1.0.1",
"_id": "fetch-errors@1.0.1",
"_from": "fetch-errors@^2.0.1",
"_id": "fetch-errors@2.0.1",
"_inBundle": false,
"_integrity": "sha512-3fCUICFQ4elSGcFYzzeip4fnio3RwixgfRJ9YUSOczax9PU/6TzdntlVZZE/q12k718OHlfRpCkWb1HHk7zf5Q==",
"_integrity": "sha512-U+pPCefRg8OwN0VARqAOCEyJs+kbSusskhW3XQPYCQMBUUNy3VtK9OYyySlybDQmMkZzqxWlGY9SjKCve1saJw==",
"_location": "/fetch-errors",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "fetch-errors@^1.0.1",
"raw": "fetch-errors@^2.0.1",
"name": "fetch-errors",
"escapedName": "fetch-errors",
"rawSpec": "^1.0.1",
"rawSpec": "^2.0.1",
"saveSpec": null,
"fetchSpec": "^1.0.1"
"fetchSpec": "^2.0.1"
},
"_requiredBy": [
"/async-neocities-tmp"
],
"_resolved": "https://registry.npmjs.org/fetch-errors/-/fetch-errors-1.0.1.tgz",
"_shasum": "a9ab245b6960b2e4a3fe8e95c1013e49dc77cb7c",
"_spec": "fetch-errors@^1.0.1",
"_resolved": "https://registry.npmjs.org/fetch-errors/-/fetch-errors-2.0.1.tgz",
"_shasum": "26616c7c22a0a386155ba8e53af27f98960e47dc",
"_spec": "fetch-errors@^2.0.1",
"_where": "/Users/bret/repos/deploy-to-neocities/node_modules/async-neocities-tmp",
"author": {
"name": "Bret Comnes",
@ -36,7 +36,6 @@
"description": "WIP - nothing to see here",
"devDependencies": {
"dependency-check": "^4.1.0",
"esm": "^3.2.25",
"node-fetch": "^2.6.0",
"npm-run-all": "^4.1.5",
"semistandard": "^14.2.0",
@ -47,7 +46,6 @@
"keywords": [],
"license": "MIT",
"main": "index.js",
"module": "main.js",
"name": "fetch-errors",
"repository": {
"type": "git",
@ -57,12 +55,12 @@
"test": "run-s test:*",
"test:deps": "dependency-check . --no-dev --no-peer",
"test:semistandard": "semistandard",
"test:tape": "tape -r esm test.js"
"test:tape": "tape test.js"
},
"semistandard": {
"ignore": [
"dist"
]
},
"version": "1.0.1"
"version": "2.0.1"
}

8
node_modules/fetch-errors/test.js generated vendored
View File

@ -1,7 +1,7 @@
import tape from 'tape';
import ptape from 'tape-promise';
import { handleResponse } from './main';
import fetch from 'node-fetch';
const tape = require('tape');
const ptape = require('tape-promise').default;
const { handleResponse } = require('.');
const fetch = require('node-fetch');
const test = ptape(tape);
test('handleResponse', async t => {

View File

@ -32,7 +32,7 @@
"dependencies": {
"@actions/core": "^1.2.2",
"@actions/github": "^2.1.0",
"async-neocities-tmp": "0.0.2"
"async-neocities-tmp": "^0.0.4"
},
"standard": {
"ignore": [