Skip to content
Back to skills

976 Group Api Error Handling Fix 5a2c9860

ASecurity

**Version Implemented:** 0.229.001

  • 9 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added October 11, 2026
developmentjavascriptjavatestingapibackend

Works with

  • api

Security analysis

A100/100

Scanned October 11, 2026

npx -y skills add tools-only/X-Skills --skill 976-group_api_error_handling_fix_5a2c9860 --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 976 Group Api Error Handling Fix 5a2c9860?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 976 Group Api Error Handling Fix 5a2c9860
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tools-only-976-group-api-error-handling-fix-5a2c9860/badge)](https://www.skillsdirectory.com/skills/tools-only-976-group-api-error-handling-fix-5a2c9860)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

SKILL.md
# GROUP_API_ERROR_HANDLING_FIX

**Version Implemented:** 0.229.001

## Issue Description
When users have group workspaces enabled but haven't selected an active group yet, the chat interface was generating JavaScript console errors from failed API calls to `/api/group_documents` and `/api/group_prompts`. These endpoints return HTTP 400 status with "No active group selected" error messages, but the JavaScript wasn't handling these specific error conditions gracefully.

**Fixed in version: 0.227.009**

## Root Cause Analysis
1. **Backend Behavior**: Both group API endpoints (`/api/group_documents` and `/api/group_prompts`) require an active group to be selected and return HTTP 400 with specific error messages when no active group is available
2. **JavaScript Error Handling**: The original `loadGroupDocs()` and `loadGroupPrompts()` functions were directly calling `.json()` on the response without checking HTTP status codes first
3. **User Experience Impact**: Users would see console errors even though the application functionality was working correctly

## Technical Details

### Files Modified
- `static/js/chat/chat-documents.js`
- `static/js/chat/chat-prompts.js`
- `config.py` (version update)

### Backend API Behavior (Preserved)
The backend APIs correctly return:
- **Group Documents**: `{'error': 'No active group selected'}` with HTTP 400
- **Group Prompts**: `{"error":"No active group selected"}` with HTTP 400

These APIs require:
- User authentication (`@login_required`)
- User validation (`@user_required`)
- Feature enabled (`@enabled_required("enable_group_workspaces")`)
- Active group selected in user settings

### JavaScript Improvements

#### Before (Problematic Code)
```javascript
// chat-documents.js
export function loadGroupDocs() {
  return fetch("/api/group_documents?page_size=1000")
    .then((r) => r.json()) // ❌ Direct .json() call without status check
    .then((data) => {
      // Handle data...
    })
    .catch((err) => {
      console.error("Error loading group docs:", err);
      groupDocs = [];
    });
}

// chat-prompts.js  
export function loadGroupPrompts() {
  return fetch("/api/group_prompts")
    .then(r => r.json()) // ❌ Direct .json() call without status check
    .then(data => {
      // Handle data...
    })
    .catch(err => console.error("Error loading group prompts:", err));
}
```

#### After (Improved Code)
```javascript
// chat-documents.js
export function loadGroupDocs() {
  return fetch("/api/group_documents?page_size=1000")
    .then((r) => {
      if (!r.ok) {
        // Handle 400 errors gracefully (e.g., no active group selected)
        if (r.status === 400) {
          console.log("No active group selected for group documents");
          groupDocs = [];
          return { documents: [] }; // Return empty result to avoid further errors
        }
        throw new Error(`HTTP ${r.status}: ${r.statusText}`);
      }
      return r.json();
    })
    .then((data) => {
      // Handle data...
    })
    .catch((err) => {
      console.error("Error loading group docs:", err);
      groupDocs = [];
    });
}

// chat-prompts.js
export function loadGroupPrompts() {
  return fetch("/api/group_prompts")
    .then(r => {
      if (!r.ok) {
        // Handle 400 errors gracefully (e.g., no active group selected)
        if (r.status === 400) {
          console.log("No active group selected for group prompts");
          groupPrompts = [];
          return { prompts: [] }; // Return empty result to avoid further errors
        }
        throw new Error(`HTTP ${r.status}: ${r.statusText}`);
      }
      return r.json();
    })
    .then(data => {
      // Handle data...
    })
    .catch(err => console.error("Error loading group prompts:", err));
}
```

## Benefits
1. **Improved User Experience**: No more JavaScript console errors when groups are enabled but no active group is selected
2. **Better Error Messaging**: Clear, informative console logging instead of cryptic JSON parsing errors
3. **Graceful Degradation**: Application continues to function normally with empty group data arrays
4. **Consistent Error Handling**: Both group APIs now handle the "no active group" scenario consistently

## Validation
The fix includes comprehensive functional testing (`test_group_error_handling_fix.py`) that validates:
- ✅ Proper HTTP status checking in JavaScript
- ✅ Specific 400 error handling for "no active group" scenarios
- ✅ Informative console logging instead of errors
- ✅ Array reset on error conditions
- ✅ Proper empty result structure return
- ✅ Backend API error conditions remain intact
- ✅ Version consistency in config.py

## User Impact
- **Before**: Users would see JavaScript console errors when groups were enabled but no active group selected
- **After**: Clean console output with informative logging, no errors visible to users
- **Functionality**: No change in application behavior, only improved error handling

## Integration Notes
This fix works seamlessly with the existing group workspace functionality:
- When a user selects an active group, the APIs will work normally
- When no group is selected, the JavaScript gracefully handles the 400 responses
- The group document and prompt dropdowns will show empty states appropriately
- No changes required to backend logic or API contracts

## Testing Recommendations
When testing group workspaces:
1. Enable group workspaces in settings
2. Visit chat interface before selecting any group
3. Check browser console - should show informative logs instead of errors
4. Select an active group - functionality should work normally
5. Deselect active group - should gracefully return to empty state without errors

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.