Skip to content

Commit 5320815

Browse files
committed
feature: update trieve-status to return the error message on the
check-crud route
1 parent 0d2c03e commit 5320815

File tree

1 file changed

+83
-39
lines changed

1 file changed

+83
-39
lines changed

src/pages/api/check-crud.js

Lines changed: 83 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,88 @@ export const POST = async ({ request }) => {
1414
let dataset_id;
1515
let organization_id;
1616

17-
const requestJSON = await request.json();
18-
let url = requestJSON.url;
19-
if (request && requestJSON.api_key) {
20-
api_key = requestJSON.api_key;
21-
};
22-
if (request && requestJSON.organization_id) {
23-
organization_id = requestJSON.organization_id;
24-
};
25-
if (request && requestJSON.dataset_id) {
26-
dataset_id = requestJSON.dataset_id;
27-
}
17+
try {
18+
const requestJSON = await request.json();
19+
let url = requestJSON.url;
20+
if (request && requestJSON.api_key) {
21+
api_key = requestJSON.api_key;
22+
};
23+
if (request && requestJSON.organization_id) {
24+
organization_id = requestJSON.organization_id;
25+
};
26+
if (request && requestJSON.dataset_id) {
27+
dataset_id = requestJSON.dataset_id;
28+
}
29+
30+
const resp = await fetch(`${url}/chunk`, {
31+
method: "POST",
32+
headers: {
33+
"Content-Type": 'application/json',
34+
"Authorization": "Bearer " + api_key,
35+
"TR-organization": organization_id,
36+
"TR-dataset": dataset_id
37+
},
38+
body: JSON.stringify({
39+
"chunk_html": "Hi there bro"
40+
})
41+
});
42+
43+
if (resp.status !== 200) {
44+
console.log(resp);
45+
return new Response(JSON.stringify({
46+
error: statusCodeResponseTypes[resp.status] || `${resp.status} Error`,
47+
"fucking": "you"
48+
}), {
49+
status: resp.status,
50+
headers: {
51+
'Content-Type': 'application/json'
52+
}
53+
});
54+
}
55+
56+
const chunkData = await resp.json();
57+
console.log(chunkData);
2858

29-
const resp = await fetch(`${url}/api/chunk`, {
30-
method: "POST",
31-
headers: {
32-
"Content-Type": 'application/json',
33-
"Authorization": api_key,
34-
"TR-organization-id": organization_id,
35-
"TR-dataset-id": dataset_id
36-
}
37-
});
38-
39-
await new Promise(resolve => setTimeout(resolve, 1000));
40-
41-
const resp2 = await fetch(`${url}/api/chunk/${resp.id}`, {
42-
method: "DELETE",
43-
headers: {
44-
"Content-Type": 'application/json',
45-
"Authorization": api_key,
46-
"TR-Organization": organization_id,
47-
"TR-Dataset": dataset_id
48-
},
49-
body: JSON.stringify({
50-
"traking_id": resp.tracking_id
51-
})
52-
});
53-
54-
return new Response(JSON.stringify({
55-
"ok": true
56-
}));
59+
await new Promise(resolve => setTimeout(resolve, 1000));
60+
61+
const resp2 = await fetch(`${url}/chunk/${chunkData.chunk_metadata.id}`, {
62+
method: "DELETE",
63+
headers: {
64+
"Content-Type": 'application/json',
65+
"Authorization": api_key,
66+
"TR-Organization": organization_id,
67+
"TR-Dataset": dataset_id
68+
},
69+
});
70+
71+
if (resp2.status !== 204) {
72+
return new Response(JSON.stringify({
73+
error: statusCodeResponseTypes[resp2.status] || `${resp2.status} Error`,
74+
}), {
75+
status: resp2.status,
76+
headers: {
77+
'Content-Type': 'application/json'
78+
}
79+
});
80+
}
81+
82+
return new Response(JSON.stringify({
83+
"ok": true
84+
}), {
85+
status: 200,
86+
headers: {
87+
'Content-Type': 'application/json'
88+
}
89+
});
90+
} catch (error) {
91+
return new Response(JSON.stringify({
92+
error: "500 Internal Server Error",
93+
message: error.message
94+
}), {
95+
status: 500,
96+
headers: {
97+
'Content-Type': 'application/json'
98+
}
99+
});
100+
}
57101
}

0 commit comments

Comments
 (0)