FirebaseDatabaseException class final
Thrown, or passed to a stream's onError, when a Realtime Database operation fails.
It extends FirebaseException with the plugin firebase_database, so on FirebaseException catch (e)
catches it too. Branch on errorCode (or on the string code); message is for people, serverStatus is for logs. Every error that
comes from the server carries a code. Programmer errors (an invalid path, value or query) are not
exceptions of this class: they are ArgumentErrors or StateErrors thrown at the call.
| Code | Meaning |
|---|---|
permission-denied |
the security rules refused the read or write |
disconnected |
the connection dropped while a sent transaction or onDisconnect request waited for its answer |
max-retries |
a transaction ran its handler 25 times and the server still refused the value |
overridden-by-set |
a write that overlaps a running transaction overrode it (DatabaseReference.runTransaction says when) |
unavailable |
the server is unavailable, or Query.get found no connection and no cache |
network-error |
the request failed for a network reason |
write-canceled |
FirebaseDatabase.purgeOutstandingWrites removed the write or transaction |
index-not-defined |
the query orders by a child that has no .indexOn rule (server status no_index) |
operation-failed |
the server reported that the operation failed (server status failure) |
too-big |
the data is larger than the server accepts in one request (server status too_big) |
database-closed |
a Future of a FirebaseDatabase that was closed, or whose app was deleted (streams end with done instead) |
data-stale |
the server answered datastale to a request other than a transaction's (a fake server can) |
unknown |
any other server status (invalid_parameters, internal_error, ...); the raw status is in serverStatus |
FlutterFire spells write-canceled as write-cancelled; the FlutterFire shim maps it.
try {
await db.ref('admin/config').set(<String, Object?>{'open': true});
} on FirebaseDatabaseException catch (e) {
if (e.errorCode == DatabaseErrorCode.permissionDenied) {
print('Not allowed.');
} else {
rethrow;
}
}
- Inheritance
-
- Object
- FirebaseException
- FirebaseDatabaseException
Constructors
- FirebaseDatabaseException({required String code, required String message, String? serverStatus, Object? cause, StackTrace? stackTrace})
-
Creates an exception with the
code(for examplepermission-denied) and amessage. The package creates them; you need this only in tests.const
Properties
- cause → Object?
-
The error that caused this one, when there is one (an error from outside the package, or the
error behind a failure the client raised itself). It is never part of message or toString: its
text may hold credentials. Where it was thrown, when the client knows, is stackTrace.
final
- code → String
-
What went wrong, in kebab case, for example
not-found.finalinherited - errorCode → DatabaseErrorCode
-
The failure as an enum, derived from code: DatabaseErrorCode.unknown for a code this version does
not know. Use it to
switchexhaustively; code stays for compatibility withFirebaseException.no setter - hashCode → int
-
The hash code for this object.
no setterinherited
- message → String?
-
A description of what went wrong.
finalinherited
- plugin → String
-
The package that threw the exception, for example
cloud_firestore.finalinherited - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- serverStatus → String?
-
The raw status and reason the server sent, for example
permission_denied: Permission denied, or null when the error did not come from the server. It never holds a token.final - stackTrace → StackTrace?
-
The stack trace captured where the exception originated, if any.
finalinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited