How to use the got.HTTPError function in got

To help you get started, we’ve selected a few got examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github poketo / poketo / src / get.js View on Github external
err => {
        const { response } = err;

        if (err instanceof got.HTTPError) {
          if (err.statusCode === 404) {
            return new errors.NotFoundError(err.url);
          }
          return new errors.HTTPError(err.statusCode, err.statusMessage, err.url);
        } else if (err instanceof got.RequestError) {
          if (err.code === 'ETIMEDOUT') {
            return new errors.TimeoutError(err.message, err.url);
          }
          return new errors.RequestError(err.url);
        }

        return new errors.PoketoError('ERROR', err.message);
      },
    ],
github panva / node-openid-client / lib / helpers / http.js View on Github external
* options.body {String|Object}
 * options.form {Boolean}
 * options.query {Object}
 * options.timeout {Number}
 * options.retries {Number}
 * options.followRedirect {Boolean}
 */
module.exports.get = function get(url, options) {
  return got.get(url, options);
};

module.exports.post = function post(url, options) {
  return got.post(url, options);
};

module.exports.HTTPError = got.HTTPError;
github jsdelivr / data.jsdelivr.com / src / routes / lib / v1 / PackageRequest.js View on Github external
}).catch((error) => {
					if (error instanceof got.HTTPError && error.response.statusCode === 403) {
						return {
							status: error.response.statusCode,
							message: error.response.body,
						};
					} else if (error instanceof got.ParseError) {
						return retry(error);
					}

					throw error;
				});
			}, { retries: 2 });
github Snooful / Snooful / utils / fetch.js View on Github external
function errorHandler(error, send, localize, type, prefix) {
	if (error instanceof got.CacheError) {
		send(safeLocal(localize, prefix, "cache_error", type));
	} else if (error instanceof got.RequestError) {
		send(safeLocal(localize, prefix, "request_error", type));
	} else if (error instanceof got.ReadError) {
		send(safeLocal(localize, prefix, "read_error", type));
	} else if (error instanceof got.ParseError) {
		send(safeLocal(localize, prefix, "parse_error", type));
	} else if (error instanceof got.HTTPError) {
		if (error.statusCode.startsWith("4")) {
			send(safeLocal(localize, prefix, "4xx_error", type, error.statusCode));
		} else if (error.statusCode.startsWith("5")) {
			send(safeLocal(localize, prefix, "5xx_error", type, error.statusCode));
		} else {
			send(safeLocal(localize, prefix, "http_error", type, error.statusCode));
		}
	} else if (error instanceof got.MaxRedirectsError) {
		send(safeLocal(localize, prefix, "redirect_error", type));
	} else if (error instanceof got.UnsupportedProtocolError) {
		send(safeLocal(localize, prefix, "protocol_error", type));
	} else if (error instanceof got.CancelError) {
		send(safeLocal(localize, prefix, "cancel_error", type));
	} else if (error instanceof got.TimeoutError) {
		send(safeLocal(localize, prefix, "timeout_error", type));
	} else {
github tidys / CocosCreatorPlugins / packages / res-compress / node_modules / bin-wrapper / node_modules / download / index.js View on Github external
readAllStream(stream, null, function (err, data) {
			if (hasHttpError) {
				return;
			}

			if (err) {
				if (err instanceof got.HTTPError) {
					hasHttpError = true;
				}

				done(err);
				return;
			}

			var dest = get.dest || this.dest();
			var fileStream = this.createStream(this.createFile(get.url, data), dest);

			fileStream.on('error', done);
			fileStream.pipe(concatStream({encoding: 'object'}, function (items) {
				files = files.concat(items);
				done();
			}));
		}.bind(this));
github fengjundev / DoubanMovie-React-Native / node_modules / react-native / node_modules / yeoman-generator / node_modules / download / index.js View on Github external
readAllStream(stream, null, function (err, data) {
			if (hasHttpError) {
				return;
			}

			if (err) {
				if (err instanceof got.HTTPError) {
					hasHttpError = true;
				}

				done(err);
				return;
			}

			var dest = get.dest || this.dest();
			var fileStream = this.createStream(this.createFile(get.url, data), dest);

			fileStream.on('error', done);
			fileStream.pipe(concatStream({encoding: 'object'}, function (items) {
				files = files.concat(items);
				done();
			}));
		}.bind(this));