{"record":{"id":"7eba4927a3a44e93","repo":"Semantic-Org/Semantic-UI","slug":"server-gave-an-error","errorCode":null,"errorMessage":"Server gave an error: ","messagePattern":"Server gave an error: ","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/definitions/behaviors/api.js","lineNumber":1140,"sourceCode":"\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: {\n    disabled : '.disabled',\n    form      : 'form'\n  },\n","sourceCodeStart":1122,"sourceCodeEnd":1158,"githubUrl":"https://github.com/Semantic-Org/Semantic-UI/blob/597843ab84d565cccfd8fd7719416350ae73e734/src/definitions/behaviors/api.js#L1122-L1158","documentation":"This error is logged by the API module's request.fail handler (api.js:576-577) when the AJAX request fails with an HTTP error status (not 200) and jQuery provides an HTTP status message (httpMessage). The message is composed by concatenating the static prefix 'Server gave an error: ' with the dynamic httpMessage (e.g., 'Internal Server Error', 'Not Found'). It is logged to console along with the request URL for diagnostics.","triggerScenarios":"The server returns any non-200 HTTP status with a standard HTTP status message. The fail handler checks xhr.status != 200 && httpMessage !== undefined && httpMessage !== ''; when all are true, it logs this composite error. Common triggers: 500 Internal Server Error, 404 Not Found, 403 Forbidden, 502 Bad Gateway.","commonSituations":"Server-side exceptions producing 500 errors. Incorrect endpoint paths producing 404s. Authentication/authorization failures (401/403). Reverse proxy timeouts (502/504). Rate limiting responses (429). These are all real server errors surfaced with HTTP status text.","solutions":["Check the server logs for the root cause of the error status.","Handle specific status codes in settings.onError for appropriate user feedback.","Ensure the endpoint URL is correct and the server is running.","For 401/403 errors, verify authentication tokens or session state."],"exampleFix":"// before\n$('.el').api({\n  url: '/api/data'\n  // no error handling\n});\n\n// after\n$('.el').api({\n  url: '/api/data',\n  onError: function(errorMessage, $module, xhr) {\n    if (xhr.status === 401) { window.location = '/login'; }\n    else if (xhr.status >= 500) { alert('Server error. Please try again later.'); }\n    else { console.error(errorMessage); }\n  }\n});","handlingStrategy":"try-catch","validationCode":"// Pre-check endpoint health before making the API call\n$.ajax({ url: '/api/health', method: 'HEAD' })\n  .done(function() { $('.el').api('query'); })\n  .fail(function(xhr) { console.error('Server returned:', xhr.status, xhr.statusText); });","typeGuard":"// Check if an XHR response is a server error\nfunction isHttpError(xhr) {\n  return xhr && xhr.status && xhr.status !== 200;\n}","tryCatchPattern":"// Handle HTTP error status messages in onError\n$('.el').api({\n  onError: function(errorMessage, $module, xhr) {\n    var statusMap = {\n      400: 'Bad request — check your input.',\n      401: 'Unauthorized — please log in.',\n      403: 'Forbidden — insufficient permissions.',\n      404: 'Not found — the resource does not exist.',\n      500: 'Internal server error — please try later.'\n    };\n    var msg = statusMap[xhr.status] || ('Server gave an error: ' + xhr.statusText);\n    console.error(msg);\n  }\n});","preventionTips":["Handle specific HTTP status codes in settings.onError for targeted user feedback.","Monitor server logs for recurring error patterns.","Implement server-side health checks and return meaningful error JSON."],"tags":["api","ajax","server-error","http-status","semantic-ui"],"backgroundTag":null,"analyzedSha":"597843ab84d565cccfd8fd7719416350ae73e734","analyzedAt":"2026-08-13T01:44:23.827Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}