Skip to content

Commit 035d2ef

Browse files
committed
Get response from data wrapper
1 parent 2a5e824 commit 035d2ef

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

ui/src/components/ApiAction.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react';
22

33
import useLocalStorage from 'react-use-localstorage';
44
import { defaultHeaders, makeCurlCommand } from '../libs/strings'
5-
import type { IAPIInfo } from '../libs/types'
5+
import type {IAPIInfo, LRDResponse} from '../libs/types'
66
import ApiActionResponse from './elements/ApiActionResponse'
77
import ApiActionRequest from './elements/ApiActionRequest'
88
import ApiActionTabs from './elements/ApiActionTabs'
@@ -130,10 +130,11 @@ export default function ApiAction(props: Props) {
130130
setResponseHeaders(JSON.stringify(Object.fromEntries(response.headers), null, 2))
131131
setSendingRequest(false)
132132
return response.text()
133-
}).then((data) => {
133+
}).then((dataString) => {
134134
let isJson = true
135+
let data
135136
try {
136-
data = JSON.parse(data)
137+
data = JSON.parse(dataString) as LRDResponse
137138
} catch (error: any) {
138139
isJson = false
139140
// do nothing
@@ -167,14 +168,10 @@ export default function ApiAction(props: Props) {
167168
modelsTimeline: data._lrd.modelsTimeline
168169
})
169170
}
170-
// remove key _lrd from response
171-
if (data && data._lrd) {
172-
delete data._lrd
173-
}
174171
if (isJson) {
175-
setResponseData(JSON.stringify(data, null, 2))
172+
setResponseData(JSON.stringify(data?.data, null, 2))
176173
} else {
177-
setResponseData(data)
174+
setResponseData(dataString)
178175
}
179176

180177
setActiveTab('response')

ui/src/libs/types.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export interface IAPIRule {
22
[key: string]: string[];
33
}
4+
45
export interface IAPIInfo {
56
uri: string;
67
middlewares: string[];
@@ -14,3 +15,18 @@ export interface IAPIInfo {
1415
group_index: number;
1516
responses: string[];
1617
}
18+
19+
export interface LRDResponse {
20+
data: unknown,
21+
_lrd: {
22+
queries: [],
23+
logs: {
24+
level: string,
25+
message: string,
26+
context: [],
27+
}[],
28+
models: [],
29+
modelsTimeline: [],
30+
memory: string,
31+
}
32+
}

0 commit comments

Comments
 (0)