mirror of
https://github.com/opentofu/setup-opentofu.git
synced 2026-12-01 04:04:28 +01:00
feat(error-handling): error notification for network failures (#94)
Signed-off-by: hoivikaj <github@hoivik.co>
This commit is contained in:
1 parent
4959f8f18c
commit
b572e07b01
7 files changed
+335
-52
No files matched your search
+23
-3
@@ -6,6 +6,7 @@
|
||||
|
||||
import { HttpClient, HttpCodes } from '@actions/http-client';
|
||||
import semver from 'semver';
|
||||
import { getErrorMessage } from './error-utils.js';
|
||||
|
||||
class Build {
|
||||
constructor (version, name) {
|
||||
@@ -44,7 +45,13 @@ async function fetchReleases (githubToken) {
|
||||
Accept: 'application/json'
|
||||
};
|
||||
|
||||
const resp = await http.get(url, headers);
|
||||
let resp;
|
||||
try {
|
||||
resp = await http.get(url, headers);
|
||||
} catch (error) {
|
||||
const cause = getErrorMessage(error);
|
||||
throw new Error(`Failed to fetch OpenTofu releases from ${url}: ${cause}`);
|
||||
}
|
||||
|
||||
if (resp.message.statusCode !== HttpCodes.OK) {
|
||||
throw new Error(
|
||||
@@ -52,8 +59,21 @@ async function fetchReleases (githubToken) {
|
||||
);
|
||||
}
|
||||
|
||||
const body = await resp.readBody();
|
||||
const releasesMeta = JSON.parse(body);
|
||||
let body;
|
||||
try {
|
||||
body = await resp.readBody();
|
||||
} catch (error) {
|
||||
const cause = getErrorMessage(error);
|
||||
throw new Error(`Failed to read releases response: ${cause}`);
|
||||
}
|
||||
|
||||
let releasesMeta;
|
||||
try {
|
||||
releasesMeta = JSON.parse(body);
|
||||
} catch (error) {
|
||||
const cause = getErrorMessage(error);
|
||||
throw new Error(`Invalid releases JSON from ${url}: ${cause}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {Array}
|
||||
|
||||
Reference in new issue
Block a user