{"record":{"id":"b9de78e6bc0c014c","repo":"Semantic-Org/Semantic-UI","slug":"the-beforesend-callback-must-return-a-settings-obj","errorCode":null,"errorMessage":"The beforeSend callback must return a settings object, beforeSend ignored.","messagePattern":"The beforeSend callback must return a settings object, beforeSend ignored\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/definitions/behaviors/api.js","lineNumber":1136,"sourceCode":"  onError     : function(errorMessage, $module) {},\n\n  // request aborted\n  onAbort     : function(errorMessage, $module) {},\n\n  successTest : false,\n\n  // errors\n  error : {\n    beforeSend        : 'The before send function has aborted the request',\n    error             : 'There was an error with your request',\n    exitConditions    : 'API Request Aborted. Exit conditions met',\n    JSONParse         : 'JSON could not be parsed during error handling',\n    legacyParameters  : 'You are using legacy API success callback names',\n    method            : 'The method you called is not defined',\n    missingAction     : 'API action used but no url was defined',\n    missingSerialize  : 'jquery-serialize-object is required to add form data to an existing data object',\n    missingURL        : 'No URL specified for api event',\n    noReturnedValue   : 'The beforeSend callback must return a settings object, beforeSend ignored.',\n    noStorage         : 'Caching responses locally requires session storage',\n    parseError        : 'There was an error parsing your request',\n    requiredParameter : 'Missing a required URL parameter: ',\n    statusMessage     : 'Server gave an error: ',\n    timeout           : 'Your request timed out'\n  },\n\n  regExp  : {\n    required : /\\{\\$*[A-z0-9]+\\}/g,\n    optional : /\\{\\/\\$*[A-z0-9]+\\}/g,\n  },\n\n  className: {\n    loading : 'loading',\n    error   : 'error'\n  },\n\n  selector: {","sourceCodeStart":1118,"sourceCodeEnd":1154,"githubUrl":"https://github.com/Semantic-Org/Semantic-UI/blob/597843ab84d565cccfd8fd7719416350ae73e734/src/definitions/behaviors/api.js#L1118-L1154","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Ensure your beforeSend callback always returns the settings object: return settings;.","If you do not need to modify settings, omit the beforeSend callback entirely rather than providing a no-op.","If you conditionally modify settings, ensure every code path returns the settings object."],"exampleFix":"// before\n$('.el').api({\n  beforeSend: function(settings) {\n    settings.url = '/api/v2/data';\n    // forgot to return settings\n  }\n});\n\n// after\n$('.el').api({\n  beforeSend: function(settings) {\n    settings.url = '/api/v2/data';\n    return settings;\n  }\n});","handlingStrategy":"validation","validationCode":"// Validate that beforeSend returns a settings object\n$('.el').api({\n  beforeSend: function(settings) {\n    settings.url = '/api/v2' + settings.url;\n    // Explicitly return — always\n    return settings;\n  }\n});\n// Wrap in a validation check\nvar originalBeforeSend = $('.el').data('settings').beforeSend;\nvar result = originalBeforeSend({ url: '/test' });\nif (result === undefined) {\n  console.error('beforeSend must return a settings object');\n}","typeGuard":"// Verify beforeSend returns a plain object or false\nfunction isBeforeSendResultValid(result) {\n  return result === false || $.isPlainObject(result);\n}","tryCatchPattern":null,"preventionTips":["Always end your beforeSend function with return settings;.","Use a linter rule (e.g., ESLint consistent-return) to catch missing return paths.","If you don't modify settings, omit beforeSend entirely."],"tags":["api","beforesend","return-value","configuration","semantic-ui"],"backgroundTag":null,"analyzedSha":"597843ab84d565cccfd8fd7719416350ae73e734","analyzedAt":"2026-08-13T01:44:23.827Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}