Skip to content

Commit

Permalink
Merge pull request #675 from ashera96/api-chat-new
Browse files Browse the repository at this point in the history
  • Loading branch information
ashera96 authored Apr 3, 2024
2 parents 8e1539f + 4076745 commit 3df5f4d
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -458,21 +458,36 @@ const ApiChat = () => {

try {
const response = await fetch(url, fetchOptions);
const data = await response.json().catch(() => ({}));
const contentType = response.headers.get('Content-Type');

if (!response.ok) {
// Check if response is JSON
if (contentType && contentType.includes('application/json')) {
const data = await response.json().catch(() => ({}));
return {
code: response.status,
path: fullPath,
headers: response.headers,
body: data,
body: data, // Return the JSON data
};
}

// Check if response is XML
if (contentType && contentType.includes('application/xml')) {
const text = await response.text();
return {
code: response.status,
path: fullPath,
headers: response.headers,
body: text, // Return the XML data
};
}

// If response is neither JSON nor XML
return {
code: response.status,
path: fullPath,
headers: response.headers,
body: data,
body: 'Unsupported Content-Type detected',
};
} catch (error) {
return {
Expand Down

0 comments on commit 3df5f4d

Please sign in to comment.