Skip to content

Commit

Permalink
fix query display response issues (#58)
Browse files Browse the repository at this point in the history
fix: query display response issues

display the response when querying a non-exists index
display the response when the response is a non-json payload

Refs: #56

---------

Signed-off-by: seven <[email protected]>
  • Loading branch information
Blankll authored May 12, 2024
1 parent 5ca6c51 commit 6d4402a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/electron/fetchApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ const fetchApi: { [key: string]: (key: string, val: unknown) => unknown } = {
agent,
});
if (result.ok) {
return { status: result.status, data: await result.json() };
const data = result.headers.get('content-type').includes('application/json')
? await result.json()
: (await result.text())?.split('\n')?.filter(Boolean);

return { status: result.status, data };
}
throw new CustomError(result.status, await result.text());
} catch (e) {
Expand Down
11 changes: 5 additions & 6 deletions src/store/connectionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,12 @@ export const useConnectionStore = defineStore('connectionStore', {
const newIndex = this.established.indices.find(
({ index: indexName }: ConnectionIndex) => indexName === index,
);
if (!newIndex) {
return;
if (newIndex) {
if (!newIndex.mapping) {
newIndex.mapping = await client.get(`/${index}/_mapping`, 'format=json');
}
this.established = { ...this.established, activeIndex: newIndex };
}
if (!newIndex.mapping) {
newIndex.mapping = await client.get(`/${index}/_mapping`, 'format=json');
}
this.established = { ...this.established, activeIndex: newIndex };
}
} catch (err) {
console.error('failed to refresh index mapping', err);
Expand Down

0 comments on commit 6d4402a

Please sign in to comment.