@@ -98,13 +98,6 @@ async function fetchEntrypointAndDocs(
98
98
entrypoint : Entrypoint [ ] ;
99
99
docs : ExpandedDoc [ ] ;
100
100
} > {
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
-
108
101
function documentLoader ( input : string ) {
109
102
return fetchJsonLd ( input , options ) . then ( ( response ) => {
110
103
if ( ! ( "body" in response ) ) {
@@ -116,32 +109,50 @@ async function fetchEntrypointAndDocs(
116
109
} ) ;
117
110
}
118
111
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
+ } ;
124
155
}
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
- } ;
145
156
}
146
157
147
158
function removeTrailingSlash ( url : string ) : string {
@@ -512,14 +523,5 @@ export default function parseHydraDocumentation(
512
523
status : response . status ,
513
524
} ;
514
525
} ,
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
- } ,
524
526
) ;
525
527
}
0 commit comments