Error Handling & Diagnostics
Lazy Appwrite provides a unified and predictable error-handling system.
All errors thrown by the library extend the LazyError class, giving developers consistent structure and maximum debuggability.
Error Categories
LazyError.CONFIG
Represents invalid configuration inputs:
- Incorrect API key
- Wrong endpoint URL
- Missing or mismatched project ID
LazyError.SYNC
Thrown during schema or infrastructure synchronization:
- Database creation failures
- Collection or attribute creation errors
- Permission or access-level mismatches
LazyError.MODEL
Represents invalid model usage or schema definition issues:
- Incorrect field types
- Unsupported attribute configurations
- Relations pointing to non-existent collections
LazyError.RUNTIME
Unexpected server-side exceptions that happen during execution but are not related to configuration or syncing.
🔥
The library never swallows errors. Every sync or runtime
failure is thrown immediately with a clear, typed LazyError.
Implementation Reference
Here is the underlying LazyError class used internally:
import { LazyErrorType } from "../types/enum";
export class LazyError extends Error {
public type: LazyErrorType;
public originalError?: any;
constructor(type: LazyErrorType, message: string, originalError?: any) {
super(message);
this.name = "LazyError";
this.type = type;
this.originalError = originalError;
}
static validation(message: string) {
return new LazyError(LazyErrorType.VALIDATION, message);
}
static timeout(message: string) {
return new LazyError(LazyErrorType.TIMEOUT, message);
}
static abort(message: string, originalError?: any) {
return new LazyError(LazyErrorType.ABORT, message, originalError);
}
static appwrite(message: string, originalError?: any) {
return new LazyError(LazyErrorType.APPWRITE, message, originalError);
}
static config(message: string, originalError?: any) {
return new LazyError(LazyErrorType.CONFIG, message, originalError);
}
}Best Practices for Catching Errors
try {
await Users.create({ name: "Paul" });
} catch (err) {
if (err instanceof LazyError) {
console.error("Error Type:", err.type);
console.error("Message:", err.message);
console.error("Original:", err.originalError);
}
throw err; // Always bubble up if you can't handle it
}Last updated on