Semantic-Org/Semantic-UI · warning

The beforeSend callback must return a settings object, befor

Error message

The beforeSend callback must return a settings object, beforeSend ignored.

What it means

This error is logged by the API module's get.settings() function (api.js:738-739) when the user's beforeSend callback returns undefined instead of a settings object or false. The module expects beforeSend to either return a modified settings object, return false (to abort), or implicitly use the original settings. When undefined is returned explicitly (function ends without return or returns undefined), it logs this warning and proceeds with the original settings.

Source

Thrown at src/definitions/behaviors/api.js:1136

  onError     : function(errorMessage, $module) {},

  // request aborted
  onAbort     : function(errorMessage, $module) {},

  successTest : false,

  // errors
  error : {
    beforeSend        : 'The before send function has aborted the request',
    error             : 'There was an error with your request',
    exitConditions    : 'API Request Aborted. Exit conditions met',
    JSONParse         : 'JSON could not be parsed during error handling',
    legacyParameters  : 'You are using legacy API success callback names',
    method            : 'The method you called is not defined',
    missingAction     : 'API action used but no url was defined',
    missingSerialize  : 'jquery-serialize-object is required to add form data to an existing data object',
    missingURL        : 'No URL specified for api event',
    noReturnedValue   : 'The beforeSend callback must return a settings object, beforeSend ignored.',
    noStorage         : 'Caching responses locally requires session storage',
    parseError        : 'There was an error parsing your request',
    requiredParameter : 'Missing a required URL parameter: ',
    statusMessage     : 'Server gave an error: ',
    timeout           : 'Your request timed out'
  },

  regExp  : {
    required : /\{\$*[A-z0-9]+\}/g,
    optional : /\{\/\$*[A-z0-9]+\}/g,
  },

  className: {
    loading : 'loading',
    error   : 'error'
  },

  selector: {

View on GitHub (pinned to 597843ab84)

Solutions

  1. Ensure your beforeSend callback always returns the settings object: return settings;.
  2. If you do not need to modify settings, omit the beforeSend callback entirely rather than providing a no-op.
  3. If you conditionally modify settings, ensure every code path returns the settings object.

Example fix

// before
$('.el').api({
  beforeSend: function(settings) {
    settings.url = '/api/v2/data';
    // forgot to return settings
  }
});

// after
$('.el').api({
  beforeSend: function(settings) {
    settings.url = '/api/v2/data';
    return settings;
  }
});
Defensive patterns

Strategy: validation

Validate before calling

// Validate that beforeSend returns a settings object
$('.el').api({
  beforeSend: function(settings) {
    settings.url = '/api/v2' + settings.url;
    // Explicitly return — always
    return settings;
  }
});
// Wrap in a validation check
var originalBeforeSend = $('.el').data('settings').beforeSend;
var result = originalBeforeSend({ url: '/test' });
if (result === undefined) {
  console.error('beforeSend must return a settings object');
}

Type guard

// Verify beforeSend returns a plain object or false
function isBeforeSendResultValid(result) {
  return result === false || $.isPlainObject(result);
}

Prevention

When it happens

Trigger: Configuring $('.el').api({ beforeSend: function(settings) { settings.url = '/new'; } }) where the function modifies settings but forgets to return it. The function returns undefined because JavaScript functions return undefined by default when no explicit return statement is hit.

Common situations: Developers modifying settings inside beforeSend without returning the modified object (a very common JavaScript mistake). Functions that conditionally modify settings and have code paths that fall through without returning. Confusion about whether beforeSend should return the settings object or mutate it in place (the module expects a return value).

Related errors


AI-assisted analysis of Semantic-Org/Semantic-UI@597843ab84 (2026-08-13). Data as JSON: /api/errors/b9de78e6bc0c014c. Report an issue: GitHub.