@@ -59,6 +59,7 @@ const showConnectorMethods = ref(true)
5959const isUserLogon = ref (true )
6060const userEntitlements = ref ([])
6161const type = ref (' ' )
62+ const isLoading = ref (false )
6263const resourceDocs = inject (obpResourceDocsKey )
6364const footNote = ref ({
6465 operationId: ' ' ,
@@ -186,43 +187,48 @@ const setType = (method) => {
186187}
187188const submitRequest = async () => {
188189 if (url .value ) {
189- switch (method .value ) {
190- case ' POST' : {
191- highlightCode (
192- await create (
193- url .value ,
194- (() => {
195- const rawBody = exampleRequestBody .value
196- const maybeBody = typeof rawBody === ' string' ? rawBody .trim () : rawBody
197- return maybeBody ? maybeBody : undefined
198- })()
190+ isLoading .value = true
191+ try {
192+ switch (method .value ) {
193+ case ' POST' : {
194+ highlightCode (
195+ await create (
196+ url .value ,
197+ (() => {
198+ const rawBody = exampleRequestBody .value
199+ const maybeBody = typeof rawBody === ' string' ? rawBody .trim () : rawBody
200+ return maybeBody ? maybeBody : undefined
201+ })()
202+ )
199203 )
200- )
201- break
202- }
203- case ' PUT ' : {
204- highlightCode (
205- await update (
206- url . value ,
207- (() => {
208- const rawBody = exampleRequestBody . value
209- const maybeBody = typeof rawBody === ' string ' ? rawBody . trim () : rawBody
210- return maybeBody ? maybeBody : undefined
211- })( )
204+ break
205+ }
206+ case ' PUT ' : {
207+ highlightCode (
208+ await update (
209+ url . value ,
210+ (() => {
211+ const rawBody = exampleRequestBody . value
212+ const maybeBody = typeof rawBody === ' string ' ? rawBody . trim () : rawBody
213+ return maybeBody ? maybeBody : undefined
214+ })()
215+ )
212216 )
213- )
214- break
215- }
216- case ' DELETE ' : {
217- highlightCode ( await discard ( url . value ))
218- break
219- }
220- default : {
221- highlightCode ( await get ( url . value ))
222- break
217+ break
218+ }
219+ case ' DELETE ' : {
220+ highlightCode ( await discard ( url . value ))
221+ break
222+ }
223+ default : {
224+ highlightCode ( await get ( url . value ))
225+ break
226+ }
223227 }
228+ responseHeaderTitle .value = ' RESPONSE'
229+ } finally {
230+ isLoading .value = false
224231 }
225- responseHeaderTitle .value = ' RESPONSE'
226232 } else {
227233 ElNotification ({
228234 duration: elMessageDuration ,
@@ -243,6 +249,11 @@ const parseDoubleEncodedJson = (obj: any): any => {
243249
244250 // If it's a string, try to parse it as JSON
245251 if (typeof obj === ' string' ) {
252+ // Skip strings that can't be JSON (must start with { [ or ")
253+ const trimmed = obj .trimStart ()
254+ if (trimmed .length === 0 || (trimmed [0 ] !== ' {' && trimmed [0 ] !== ' [' && trimmed [0 ] !== ' "' )) {
255+ return obj
256+ }
246257 try {
247258 const parsed = JSON .parse (obj )
248259 // Recursively parse the result in case it's triple-encoded or more
@@ -279,20 +290,28 @@ const highlightCode = (json) => {
279290 return
280291 }
281292
293+ let dataToFormat
282294 if (json .error ) {
283- // Parse double-encoded JSON error messages to display them cleanly
284- const errorObj = parseDoubleEncodedJson (json .error )
295+ dataToFormat = parseDoubleEncodedJson (json .error )
296+ } else {
297+ dataToFormat = parseDoubleEncodedJson (json )
298+ }
285299
286- // Display the full OBP error object with proper formatting
287- successResponseBody .value = hljs .lineNumbersValue (
288- hljs .highlightAuto (JSON .stringify (errorObj , null , 4 ), [' JSON' ]).value
289- )
300+ const jsonString = JSON .stringify (dataToFormat , null , 4 )
301+
302+ // For large responses, show plain text without highlighting to avoid freezing the UI
303+ if (jsonString .length > 50000 ) {
304+ successResponseBody .value = jsonString .replace (/ &/ g , ' &' ).replace (/ </ g , ' <' ).replace (/ >/ g , ' >' )
305+ return
306+ }
307+
308+ const highlighted = hljs .highlight (jsonString , { language: ' json' }).value
309+ const lineCount = jsonString .split (' \n ' ).length
310+
311+ if (lineCount > 500 ) {
312+ successResponseBody .value = highlighted
290313 } else {
291- // Parse double-encoded JSON in successful responses too
292- const parsedJson = parseDoubleEncodedJson (json )
293- successResponseBody .value = hljs .lineNumbersValue (
294- hljs .highlightAuto (JSON .stringify (parsedJson , null , 4 ), [' JSON' ]).value
295- )
314+ successResponseBody .value = hljs .lineNumbersValue (highlighted )
296315 }
297316}
298317const submitSingleEntitlement = async (formRole : any , idx : number ) => {
@@ -701,6 +720,7 @@ const onError = (error) => {
701720 />
702721 <el-button
703722 :type =" type"
723+ :loading =" isLoading"
704724 id =" search-button"
705725 @click =" submit(requestFormRef, submitRequest)"
706726 >{{ method }}</el-button
@@ -858,6 +878,7 @@ span {
858878pre {
859879 padding : 0px 30px 0px 30px ;
860880 max-height : 340px ;
881+ overflow : auto ;
861882 background-color : #253047 ;
862883 font-size : 14px ;
863884 margin : 0 ;
0 commit comments