The library uses a combination of return values and exceptions to handle errors.
- Initialization Failure:
initialize()orinitControl()methods will returnfalseif the connection cannot be established or verified. - Network Errors: Lower-level network issues (timeouts, unreachable host) are often caught and logged to the console, with the method returning
nullorfalse. - Keep-Alive Failures: The TCP client maintains a keep-alive loop. If it fails repeatedly, the connection is considered lost, and the client may attempt to reconnect or stop the keep-alive process.
- HTTP Status Codes: The
FiveMClientchecks HTTP status codes. Non-200 responses are treated as failures. - Printer Error Codes: The
FFMachineInfoobject contains anErrorCodeproperty. This string comes directly from the printer and indicates internal hardware or firmware errors (e.g., "File Error", "Sensor Error").
-
Check Return Values: Most control methods return a
booleanindicating success or failure. Always check this result.if (!await client.control.setLedOn()) { console.error("Failed to turn on LED"); }
-
Handle Nulls: Data retrieval methods (like
info.get()) may returnnullif the request fails.const status = await client.info.get(); if (status) { console.log(status.Status); } else { console.log("Could not retrieve status"); }
-
Verify Connection: Before performing critical operations, you can use
client.verifyConnection()to ensure the printer is still reachable. -
Try-Catch: When using methods that perform file I/O (like
uploadFile), wrap calls in atry-catchblock to handle file system errors.