ragged-chat-sdk 1.0.10 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +16 -3
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -39,6 +39,11 @@ export function init(config = {}) {
39
39
  async function fetchConfig() {
40
40
  try {
41
41
  const response = await fetch(`${API_URL}/chat/${subdomain}/config`);
42
+ if (!response.ok) {
43
+ const errorData = await response.json().catch(() => ({}));
44
+ console.error('[Ragged SDK] Config Error:', response.status, errorData.error || response.statusText);
45
+ return;
46
+ }
42
47
  chatConfig = await response.json();
43
48
  } catch (error) {
44
49
  console.error('[Ragged SDK] Failed to fetch config:', error);
@@ -53,14 +58,22 @@ export function init(config = {}) {
53
58
  headers: { 'Content-Type': 'application/json' },
54
59
  body: JSON.stringify({ message, history: messages })
55
60
  });
56
- const data = await response.json();
61
+
62
+ const data = await response.json().catch(() => ({ error: 'Unknown Server Error' }));
63
+
64
+ if (!response.ok) {
65
+ console.error('[Ragged SDK] Chat Error:', response.status, data.error || response.statusText);
66
+ return data.details || data.error || "Sorry, I'm having trouble processing that right now. Please try again later.";
67
+ }
68
+
57
69
  return data.response;
58
70
  } catch (error) {
59
- console.error('[Ragged SDK] Failed to send message:', error);
60
- return "Sorry, I'm having trouble connecting right now.";
71
+ console.error('[Ragged SDK] Network Error:', error);
72
+ return "Sorry, I'm having trouble connecting to the server. Please check your internet connection.";
61
73
  }
62
74
  }
63
75
 
76
+
64
77
  // Switch between tabs
65
78
  function switchTab(tabId) {
66
79
  activeTab = tabId;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ragged-chat-sdk",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "Official SDK for integrating Ragged Chatbots into your website.",
5
5
  "type": "module",
6
6
  "main": "index.js",