Semantic-Org/Semantic-UI · error
Server gave an error:
Error message
Server gave an error:
What it means
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.
Source
Thrown at src/definitions/behaviors/api.js:1140
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: {
disabled : '.disabled',
form : 'form'
},
View on GitHub (pinned to 597843ab84)
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.
Example fix
// before
$('.el').api({
url: '/api/data'
// no error handling
});
// after
$('.el').api({
url: '/api/data',
onError: function(errorMessage, $module, xhr) {
if (xhr.status === 401) { window.location = '/login'; }
else if (xhr.status >= 500) { alert('Server error. Please try again later.'); }
else { console.error(errorMessage); }
}
}); Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-check endpoint health before making the API call
$.ajax({ url: '/api/health', method: 'HEAD' })
.done(function() { $('.el').api('query'); })
.fail(function(xhr) { console.error('Server returned:', xhr.status, xhr.statusText); }); Type guard
// Check if an XHR response is a server error
function isHttpError(xhr) {
return xhr && xhr.status && xhr.status !== 200;
} Try / catch
// Handle HTTP error status messages in onError
$('.el').api({
onError: function(errorMessage, $module, xhr) {
var statusMap = {
400: 'Bad request — check your input.',
401: 'Unauthorized — please log in.',
403: 'Forbidden — insufficient permissions.',
404: 'Not found — the resource does not exist.',
500: 'Internal server error — please try later.'
};
var msg = statusMap[xhr.status] || ('Server gave an error: ' + xhr.statusText);
console.error(msg);
}
}); Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- There was an error with your request
- The before send function has aborted the request
- JSON could not be parsed during error handling
- No URL specified for api event
- There was an error parsing your request
AI-assisted analysis of Semantic-Org/Semantic-UI@597843ab84 (2026-08-13).
Data as JSON: /api/errors/7eba4927a3a44e93.
Report an issue: GitHub.