Skip to content

Commit add57c8

Browse files
committed
fix(oxlint): promise/prefer-await-to-callbacks + eslint/no-inner-declarations
1 parent eb82a83 commit add57c8

File tree

1 file changed

+43
-41
lines changed

1 file changed

+43
-41
lines changed

src/hydra/parseHydraDocumentation.ts

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,6 @@ async function fetchEntrypointAndDocs(
9898
entrypoint: Entrypoint[];
9999
docs: ExpandedDoc[];
100100
}> {
101-
const d = await fetchJsonLd(entrypointUrl, options);
102-
if (!("body" in d)) {
103-
throw new Error("An empty response was received for the entrypoint URL.");
104-
}
105-
const entrypointJsonLd = d.body;
106-
const docsUrl = getDocumentationUrlFromHeaders(d.response.headers);
107-
108101
function documentLoader(input: string) {
109102
return fetchJsonLd(input, options).then((response) => {
110103
if (!("body" in response)) {
@@ -116,32 +109,50 @@ async function fetchEntrypointAndDocs(
116109
});
117110
}
118111

119-
const docsResponse = await fetchJsonLd(docsUrl, options);
120-
if (!("body" in docsResponse)) {
121-
throw new Error(
122-
"An empty response was received for the documentation URL.",
123-
);
112+
try {
113+
const d = await fetchJsonLd(entrypointUrl, options);
114+
if (!("body" in d)) {
115+
throw new Error("An empty response was received for the entrypoint URL.");
116+
}
117+
const entrypointJsonLd = d.body;
118+
const docsUrl = getDocumentationUrlFromHeaders(d.response.headers);
119+
120+
const docsResponse = await fetchJsonLd(docsUrl, options);
121+
if (!("body" in docsResponse)) {
122+
throw new Error(
123+
"An empty response was received for the documentation URL.",
124+
);
125+
}
126+
const docsJsonLd = docsResponse.body;
127+
128+
const [docs, entrypoint] = (await Promise.all([
129+
jsonld.expand(docsJsonLd, {
130+
base: docsUrl,
131+
documentLoader,
132+
}),
133+
jsonld.expand(entrypointJsonLd, {
134+
base: entrypointUrl,
135+
documentLoader,
136+
}),
137+
])) as unknown as [ExpandedDoc[], Entrypoint[]];
138+
139+
return {
140+
entrypointUrl,
141+
docsUrl,
142+
entrypoint,
143+
response: d.response,
144+
docs,
145+
};
146+
} catch (error) {
147+
const { response } = error as { response: Response };
148+
// oxlint-disable-next-line no-throw-literal
149+
throw {
150+
api: new Api(entrypointUrl, { resources: [] }),
151+
error,
152+
response,
153+
status: get(response, "status"),
154+
};
124155
}
125-
const docsJsonLd = docsResponse.body;
126-
127-
const [docs, entrypoint] = (await Promise.all([
128-
jsonld.expand(docsJsonLd, {
129-
base: docsUrl,
130-
documentLoader,
131-
}),
132-
jsonld.expand(entrypointJsonLd, {
133-
base: entrypointUrl,
134-
documentLoader,
135-
}),
136-
])) as unknown as [ExpandedDoc[], Entrypoint[]];
137-
138-
return {
139-
entrypointUrl,
140-
docsUrl,
141-
entrypoint,
142-
response: d.response,
143-
docs,
144-
};
145156
}
146157

147158
function removeTrailingSlash(url: string): string {
@@ -512,14 +523,5 @@ export default function parseHydraDocumentation(
512523
status: response.status,
513524
};
514525
},
515-
(error: { response: Response }) => {
516-
// oxlint-disable-next-line no-throw-literal
517-
throw {
518-
api: new Api(entrypointUrl, { resources: [] }),
519-
error,
520-
response: error.response,
521-
status: get(error.response, "status"),
522-
};
523-
},
524526
);
525527
}

0 commit comments

Comments
 (0)