Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6683,7 +6683,8 @@ var require_client = /* @__PURE__ */ __commonJSMin(((exports, module) => {
this.once("connect", cb);
}
[kDispatch](opts, handler) {
const request = new Request(opts.origin || this[kUrl].origin, opts, handler);
const origin = opts.origin || this[kUrl].origin;
const request = new Request(origin, opts, handler);
this[kQueue].push(request);
if (this[kResuming]) {} else if (util.bodyLength(request.body) == null && util.isIterable(request.body)) {
this[kResuming] = 1;
Expand Down Expand Up @@ -8981,7 +8982,10 @@ var require_mock_utils = /* @__PURE__ */ __commonJSMin(((exports, module) => {
matchedMockDispatches = matchedMockDispatches.filter(({ body }) => typeof body !== "undefined" ? matchValue(body, key.body) : true);
if (matchedMockDispatches.length === 0) throw new MockNotMatchedError(`Mock dispatch not matched for body '${key.body}' on path '${resolvedPath}'`);
matchedMockDispatches = matchedMockDispatches.filter((mockDispatch) => matchHeaders(mockDispatch, key.headers));
if (matchedMockDispatches.length === 0) throw new MockNotMatchedError(`Mock dispatch not matched for headers '${typeof key.headers === "object" ? JSON.stringify(key.headers) : key.headers}' on path '${resolvedPath}'`);
if (matchedMockDispatches.length === 0) {
const headers = typeof key.headers === "object" ? JSON.stringify(key.headers) : key.headers;
throw new MockNotMatchedError(`Mock dispatch not matched for headers '${headers}' on path '${resolvedPath}'`);
}
return matchedMockDispatches[0];
}
function addMockDispatch(mockDispatches, key, data) {
Expand Down Expand Up @@ -10300,7 +10304,8 @@ var require_response = /* @__PURE__ */ __commonJSMin(((exports, module) => {
static json(data, init = {}) {
webidl.argumentLengthCheck(arguments, 1, "Response.json");
if (init !== null) init = webidl.converters.ResponseInit(init);
const body = extractBody(textEncoder.encode(serializeJavascriptValueToJSONString(data)));
const bytes = textEncoder.encode(serializeJavascriptValueToJSONString(data));
const body = extractBody(bytes);
const responseObject = fromInnerResponse(makeResponse({}), "response");
initializeResponse(responseObject, init, {
body: body[0],
Expand Down Expand Up @@ -11269,7 +11274,8 @@ var require_fetch = /* @__PURE__ */ __commonJSMin(((exports, module) => {
taskDestination = request.client.globalObject;
crossOriginIsolatedCapability = request.client.crossOriginIsolatedCapability;
}
const timingInfo = createOpaqueTimingInfo({ startTime: coarsenedSharedCurrentTime(crossOriginIsolatedCapability) });
const currentTime = coarsenedSharedCurrentTime(crossOriginIsolatedCapability);
const timingInfo = createOpaqueTimingInfo({ startTime: currentTime });
const fetchParams = {
controller: new Fetch(dispatcher),
request,
Expand Down Expand Up @@ -11377,7 +11383,8 @@ var require_fetch = /* @__PURE__ */ __commonJSMin(((exports, module) => {
response.headersList.set("content-type", type, true);
} else {
response.rangeRequested = true;
const rangeValue = simpleRangeHeaderValue(request.headersList.get("range", true), true);
const rangeHeader = request.headersList.get("range", true);
const rangeValue = simpleRangeHeaderValue(rangeHeader, true);
if (rangeValue === "failure") return Promise.resolve(makeNetworkError("failed to fetch the data URL"));
let { rangeStartValue: rangeStart, rangeEndValue: rangeEnd } = rangeValue;
if (rangeStart === null) {
Expand All @@ -11400,7 +11407,8 @@ var require_fetch = /* @__PURE__ */ __commonJSMin(((exports, module) => {
return Promise.resolve(response);
}
case "data:": {
const dataURLStruct = dataURLProcessor(requestCurrentURL(request));
const currentURL = requestCurrentURL(request);
const dataURLStruct = dataURLProcessor(currentURL);
if (dataURLStruct === "failure") return Promise.resolve(makeNetworkError("failed to fetch the data URL"));
const mimeType = serializeAMimeType(dataURLStruct.mimeType);
return Promise.resolve(makeResponse({
Expand Down Expand Up @@ -12759,8 +12767,10 @@ var require_cache = /* @__PURE__ */ __commonJSMin(((exports, module) => {
});
const clonedResponse = cloneResponse(innerResponse);
const bodyReadPromise = createDeferredPromise();
if (innerResponse.body != null) readAllBytes(innerResponse.body.stream.getReader()).then(bodyReadPromise.resolve, bodyReadPromise.reject);
else bodyReadPromise.resolve(void 0);
if (innerResponse.body != null) {
const reader = innerResponse.body.stream.getReader();
readAllBytes(reader).then(bodyReadPromise.resolve, bodyReadPromise.reject);
} else bodyReadPromise.resolve(void 0);
/** @type {CacheBatchOperation[]} */
const operations = [];
/** @type {CacheBatchOperation} */
Expand Down Expand Up @@ -13052,7 +13062,10 @@ var require_cachestorage = /* @__PURE__ */ __commonJSMin(((exports, module) => {
request = webidl.converters.RequestInfo(request);
options = webidl.converters.MultiCacheQueryOptions(options);
if (options.cacheName != null) {
if (this.#caches.has(options.cacheName)) return await new Cache(kConstruct, this.#caches.get(options.cacheName)).match(request, options);
if (this.#caches.has(options.cacheName)) {
const cacheList = this.#caches.get(options.cacheName);
return await new Cache(kConstruct, cacheList).match(request, options);
}
} else for (const cacheList of this.#caches.values()) {
const response = await new Cache(kConstruct, cacheList).match(request, options);
if (response !== void 0) return response;
Expand Down Expand Up @@ -13080,7 +13093,10 @@ var require_cachestorage = /* @__PURE__ */ __commonJSMin(((exports, module) => {
const prefix = "CacheStorage.open";
webidl.argumentLengthCheck(arguments, 1, prefix);
cacheName = webidl.converters.DOMString(cacheName, prefix, "cacheName");
if (this.#caches.has(cacheName)) return new Cache(kConstruct, this.#caches.get(cacheName));
if (this.#caches.has(cacheName)) {
const cache = this.#caches.get(cacheName);
return new Cache(kConstruct, cache);
}
const cache = [];
this.#caches.set(cacheName, cache);
return new Cache(kConstruct, cache);
Expand Down Expand Up @@ -17113,7 +17129,10 @@ async function run() {
}
}
function extractMessage(json) {
if (json !== null && typeof json === "object" && "message" in json && typeof json.message === "string") return json.message;
if (json === null || typeof json !== "object") return;
const record = json;
if (typeof record.message === "string") return record.message;
if (typeof record.error === "string") return record.error;
}
//#endregion
//#region src/index.ts
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,19 @@ describe("run()", () => {
);
});

test("uses error field from response body when message is absent", async () => {
fetchMock.mock.mockImplementation(async () =>
makeResponse(false, 403, {
error: 'no repository with GitHub Actions OIDC enabled matches "owner/repo"',
}),
);
await run();
assert.equal(
setFailedMock.mock.calls[0]?.arguments[0],
'Can not start deployment. Hub returned HTTP 403: no repository with GitHub Actions OIDC enabled matches "owner/repo"',
);
});

test("falls back to (empty body) when error response has no message", async () => {
fetchMock.mock.mockImplementation(async () => makeResponse(false, 500, {}));
await run();
Expand Down
17 changes: 10 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,15 @@ export async function run(): Promise<void> {
}

function extractMessage(json: unknown): string | undefined {
if (
json !== null &&
typeof json === "object" &&
"message" in json &&
typeof (json as Record<string, unknown>).message === "string"
) {
return (json as Record<string, string>).message;
if (json === null || typeof json !== "object") {
return undefined;
}

const record = json as Record<string, unknown>;
if (typeof record.message === "string") {
return record.message;
}
if (typeof record.error === "string") {
return record.error;
}
}