
Show what you know, not what you assume
When an application cannot reach a server, it may be tempting to display “You are offline.” But a failed request does not, by itself, prove that the member’s device has lost its network connection. The server may be unavailable, a connection may be refused, or a request may have taken too long.
This distinction matters because the next step depends on the cause. A member who has a network connection but cannot reach one service may need to retry later or contact the service owner. A member whose device has no network connection may need to reconnect. An accurate message helps them choose the right action.
Understand the symptom
Suppose a page or feature makes a request and gets no usable response. The application reports a connection problem and labels the member offline. That label may be misleading if all the application knows is that one request failed.
Keep these states separate:
- Request failed: The application did not get the response it needed. This is the safest general description when the cause is unknown.
- Server or connection problem: The error gives evidence of a timeout, refusal, or other failure while contacting the service.
- Offline: Use this only when your application has a reliable basis for concluding that the device has no network connection. Even then, make clear that this is a device connectivity signal, not proof that every possible service is unreachable.
Exact error names and network signals depend on the language, runtime, library, and operating system. Treat the examples below as general patterns, not as a guarantee that every platform reports failures in the same way.
Likely causes
- The server did not respond in time. It may be slow, overloaded, unreachable from the client, or blocked somewhere on the route. A timeout says the request did not complete within the client’s limit; it does not identify the underlying reason by itself.
- The connection was refused. The destination may be reachable, but nothing is accepting the connection on the requested address and port, or an intermediary rejected it. Check the service status, host, port, and configuration.
- The server or an upstream dependency failed. The application may be able to contact the server but receive a failure response, or the server may fail before it can return one. Check the response and server-side logs if you have access.
- The client configuration is wrong. A mistyped hostname, incorrect port, proxy setting, certificate configuration, or environment-specific endpoint can prevent a request from succeeding.
- The device really has no network connection. This is possible, but it is only one explanation. Do not infer it from a single failed request to one service.
Minimal example: preserve the uncertainty
The following JavaScript example illustrates the message-handling principle. It uses a generic fetch request and does not attempt to identify the precise cause of every failure. It is an illustrative example, not a tested result.
async function loadMemberData() {
try {
const response = await fetch("/api/member");
if (!response.ok) {
showMessage("The service could not complete your request. Please try again.");
return;
}
const data = await response.json();
renderMemberData(data);
} catch (error) {
// A failed request alone does not prove that the device is offline.
showMessage("We could not reach the service. Check your connection or try again.");
logRequestFailure(error);
}
}
Here, showMessage, renderMemberData, and logRequestFailure stand for functions in your own application. The catch block avoids claiming that the member is offline. If your application can reliably distinguish specific conditions, it can show a more specific message—but it should not guess based on an ambiguous failure.
Diagnose the failure step by step
-
Record what failed.
Capture the operation, destination category, time, and error details available to your application. Avoid logging secrets such as access tokens or sensitive request bodies. Use a request identifier if your system supports correlating client reports with server logs.
-
Check whether the server returned a response.
If there is an HTTP response, inspect its status and relevant server-side logs. A response indicating failure is different from a request that never received a response. Do not treat every unsuccessful response as proof of an offline device.
-
Look at the actual failure category.
Determine whether the request timed out, the connection was refused, name resolution failed, or another error occurred. Use the documentation for the specific runtime or networking library in your project. Error representations differ between platforms and versions.
-
Check the endpoint and environment.
Confirm that the application is using the intended hostname, port, and environment. Compare the client configuration with the service configuration. If a proxy, gateway, or load balancer is involved, include it in the investigation rather than assuming the application is talking directly to the server.
-
Check server health separately from client connectivity.
If you maintain the service, inspect its availability and logs around the failure time. If you do not maintain it, avoid implying that the member can fix a server-side problem by reconnecting their device.
-
Choose the least assumptive message.
When the cause is not known, say that the request failed or the service could not be reached. Give a useful next step, such as retrying, checking the connection, or trying again later. Only use “offline” when your application has a sound reason to report that device state.
Make the fix safe and version-aware
Do not build error handling around a guessed error string or a single platform-specific exception name. First check the current official documentation for the runtime or networking library you use. Confirm how that version represents timeouts, refused connections, unsuccessful responses, and device connectivity signals.
Then make the smallest suitable change:
- Use a neutral fallback message when the cause is uncertain.
- Handle known failure categories separately only when the platform provides a dependable way to distinguish them.
- Keep server responses, transport failures, and device connectivity signals as separate states in your application logic.
- Do not automatically retry every failure indefinitely. If you add retries, make them bounded and appropriate to the operation; repeating a request that changes data may have unintended effects.
- Keep diagnostic logging useful but free of credentials and unnecessary personal information.
The source material supplied for this guide does not establish a particular library version or prescribe an API. Check the documentation for the exact dependencies and platform versions in your project before adopting version-specific code.
Verify the change
Test the message and error-handling logic under distinct conditions rather than relying on one successful request. Where practical, use a development environment or controlled test doubles to simulate outcomes.
- Successful response: Confirm the application continues to display the expected data.
- Unsuccessful server response: Confirm the application reports a service or request problem, not a confirmed offline state.
- Timeout or refused connection: Confirm the message is useful and does not claim more than the error establishes.
- Known device connectivity loss: If your application has a reliable way to identify this state, check that the offline message is used only for that condition.
- Recovery: Restore the service or connection and confirm that the member can retry or continue without being stuck in a stale error state.
These are verification steps, not a claim that the example above has been run or tested. The exact setup depends on your application’s stack.
Common follow-up questions
Can I use a browser’s online status to prove that my server is reachable?
No single general device-connectivity signal should be treated as proof that a specific service is reachable. A device can have network access while one server is unavailable, and a connectivity indicator may not describe every route or service. Use service-specific request results to describe service reachability, and use device-level signals only for the narrower claim they support.
Should every failed request offer a retry?
Not necessarily. A retry can help with a temporary problem, but it may not help when the endpoint is misconfigured or the service remains unavailable. For operations that change data, consider whether repeating the request could repeat the action. Provide a clear retry option when it is appropriate, and avoid automatic, unlimited retries.
References
- GitHub issue supplied as the topic source
- Research reference supplied in the brief (a question index, not version-specific technical documentation)
Consult the current official documentation for your application’s language, networking library, and operating system before relying on specific error codes or APIs.
Dont SPAM