{"record":{"id":"f865e5ffd75bb2ad","repo":"Semantic-Org/Semantic-UI","slug":"the-before-send-function-has-aborted-the-request","errorCode":null,"errorMessage":"The before send function has aborted the request","messagePattern":"The before send function has aborted the request","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/definitions/behaviors/api.js","lineNumber":1127,"sourceCode":"  onSuccess   : function(response, $module) {},\n\n  // request finished without aborting\n  onComplete  : function(response, $module) {},\n\n  // failed JSON success test\n  onFailure   : function(response, $module) {},\n\n  // server error\n  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,","sourceCodeStart":1109,"sourceCodeEnd":1145,"githubUrl":"https://github.com/Semantic-Org/Semantic-UI/blob/597843ab84d565cccfd8fd7719416350ae73e734/src/definitions/behaviors/api.js#L1109-L1145","documentation":"This error is logged by Semantic UI's API module when the user-provided beforeSend callback (settings.beforeSend) returns exactly false, which the module interprets as an intentional abort signal. The query() function at api.js:201-208 calls module.get.settings() which invokes settings.beforeSend.call(context, settings); if that returns false, module.error(error.beforeSend) fires and the request is cancelled before it is sent.","triggerScenarios":"Configuring settings.beforeSend as a function that returns false under certain conditions (e.g., validation failure, duplicate prevention). The callback is expected to return a settings object or undefined (to use defaults); returning false is the documented abort mechanism.","commonSituations":"A beforeSend callback with a code path that unintentionally returns false (missing return statement or early-exit guard). Using beforeSend for pre-request validation that rejects the request. Confusion between beforeXHR (jQuery-level) and beforeSend (API-level) callbacks.","solutions":["If the abort is intentional, this error is expected — handle it via settings.onAbort callback instead of relying on the console message.","Ensure your beforeSend callback returns a settings object (modified or unmodified) when you want the request to proceed.","If using beforeXHR for jQuery-level interception, do not confuse it with settings.beforeSend — they serve different layers."],"exampleFix":"// before\n$('.api-element')\n  .api({\n    beforeSend: function(settings) {\n      if (!isValid()) return false; // aborts, logs error\n      return settings;\n    }\n  });\n\n// after (handle abort gracefully)\n$('.api-element')\n  .api({\n    beforeSend: function(settings) {\n      if (!isValid()) { return false; }\n      return settings;\n    },\n    onAbort: function(errorMessage) { console.warn('Aborted:', errorMessage); }\n  });","handlingStrategy":"validation","validationCode":"// Validate beforeSend return value before relying on it\n$('.el').api({\n  beforeSend: function(settings) {\n    if (!shouldProceed(settings)) {\n      // Intentional abort — handle via onAbort\n      return false;\n    }\n    // Always return a settings object for normal flow\n    return settings;\n  },\n  onAbort: function() { console.log('Request was intentionally aborted.'); }\n});","typeGuard":"// Verify beforeSend returns a valid settings object or false\nfunction validateBeforeSendResult(result) {\n  return result === false || ($.isPlainObject(result));\n}","tryCatchPattern":"// Wrap API calls that may abort in a promise chain\ntry {\n  $('.el').api('query');\n} catch (e) {\n  // module.error logs to console; no exception is thrown\n  // Handle programmatically if needed\n}","preventionTips":["Always return the settings object from beforeSend when you want the request to proceed.","Use the onAbort callback to handle intentional aborts gracefully.","Do not confuse settings.beforeSend (API-level) with settings.beforeXHR (jQuery-level)."],"tags":["api","beforesend","abort","ajax","semantic-ui"],"backgroundTag":null,"analyzedSha":"597843ab84d565cccfd8fd7719416350ae73e734","analyzedAt":"2026-08-13T01:44:23.827Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}