Skip to content

2026 06 10 Security Missing Error Handling

Paulo Gomes da Cruz Junior edited this page Jun 10, 2026 · 1 revision

Security: Missing Error Handling in API Calls

Category: Security - Error Handling / Robustness Effort: Low Priority: Low Component: frontend/src/components/waste/WasteSearch/WasteSearchFiltersAdvanced/AdvancedFilterClientInput/index.tsx


Description

The onAutoCompleteChange handler makes an API call without any error handling:

onAutoCompleteChange={async (value) =>
  (await APIs.forestclient.searchForestClients(value, 0, 10)).map(...)

If the API call fails (network error, server error, timeout, etc.), the error will:

  1. Bubble up to React's rendering, potentially causing a component crash
  2. Show a raw error message to the user (poor UX)
  3. Potentially expose sensitive error details (security information disclosure)
  4. Leave the autocomplete in a broken state

Suggested Fix

Option 1: Basic Try/Catch with Empty Fallback (Recommended)

onAutoCompleteChange={async (value) => {
  try {
    const results = await APIs.forestclient.searchForestClients(value, 0, 10);
    return results.map(forestClientAutocompleteResult2CodeDescription);
  } catch (error) {
    console.error('Failed to fetch forest clients:', error);
    return []; // Return empty array to keep UI functional
  }
}}

Option 2: With User Feedback

const [fetchError, setFetchError] = useState<string | null>(null);

// In the component:
onAutoCompleteChange={async (value) => {
  try {
    setFetchError(null);
    const results = await APIs.forestclient.searchForestClients(value, 0, 10);
    return results.map(forestClientAutocompleteResult2CodeDescription);
  } catch (error) {
    console.error('Failed to fetch forest clients:', error);
    setFetchError('Failed to load clients. Please try again.');
    return [];
  }
}}

// Add error display in JSX:
{fetchError && <InlineNotification kind="error" title="Error" subtitle={fetchError} />}

Option 3: With Retry Logic

const MAX_RETRIES = 2;

onAutoCompleteChange={async (value, retryCount = 0) => {
  try {
    const results = await APIs.forestclient.searchForestClients(value, 0, 10);
    return results.map(forestClientAutocompleteResult2CodeDescription);
  } catch (error) {
    console.error('Failed to fetch forest clients:', error);
    if (retryCount < MAX_RETRIES) {
      return onAutoCompleteChange(value, retryCount + 1);
    }
    return [];
  }
}}

Related Files

  • frontend/src/components/waste/WasteSearch/WasteSearchFiltersAdvanced/AdvancedFilterClientInput/index.tsx
  • frontend/src/services/APIs.ts (check if searchForestClients has its own error handling)

Testing

  • Test with network errors (use Chrome dev tools to throttle network)
  • Test with server 500 errors
  • Test with malformed API responses
  • Verify that the UI remains functional after errors
  • Check that no sensitive error details are shown to users

Waste Plus Wiki

Home

Architecture

Codes

Decisions

Knowledge Base

Development

Changes

Clone this wiki locally