Record Class GeolocationError
java.lang.Object
java.lang.Record
com.vaadin.flow.component.geolocation.GeolocationError
- Record Components:
code- the raw numeric error code as reported by the browser. Applications should usually callerrorCode()instead of comparing this directlymessage- a human-readable message from the browser. Mainly useful for logging — the wording is not standardised and should not be shown to end users as-is
- All Implemented Interfaces:
GeolocationResult,Serializable
public record GeolocationError(int code, String message)
extends Record
implements GeolocationResult
A failed location reading: the request did not produce a
GeolocationPosition.
This is one of the three possible values of a
GeolocationTracker.value() signal, and one of the two values a
Geolocation.get(com.vaadin.flow.function.SerializableConsumer<com.vaadin.flow.component.geolocation.GeolocationResult>) callback can receive. Typical application code
switches on errorCode() to react to the specific reason:
ui.getGeolocation().get(result -> {
if (result instanceof GeolocationError err) {
switch (err.errorCode()) {
case PERMISSION_DENIED ->
showExplanation("Location is blocked for this site.");
case POSITION_UNAVAILABLE ->
showRetry("Could not determine your location.");
case TIMEOUT -> showRetry("Location request took too long.");
case UNKNOWN -> showGenericError(err.message());
}
}
});
The raw numeric code() is also exposed for logging and for safe
handling of future browser codes that the enum does not yet know about.- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionGeolocationError(int code, String message) Creates an instance of aGeolocationErrorrecord class. -
Method Summary
Modifier and TypeMethodDescriptionintcode()Returns the value of thecoderecord component.final booleanIndicates whether some other object is "equal to" this one.Returns the error reason as a typed enum suitable for exhaustiveswitch.final inthashCode()Returns a hash code value for this object.message()Returns the value of themessagerecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
Method Details
-
errorCode
Returns the error reason as a typed enum suitable for exhaustiveswitch. ReturnsGeolocationErrorCode.UNKNOWNif the browser reports a numeric code this version of Flow does not recognise.- Returns:
- the matching
GeolocationErrorCode, orGeolocationErrorCode.UNKNOWNwhen the rawcode()is not one of the known values
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
code
public int code()Returns the value of thecoderecord component.- Returns:
- the value of the
coderecord component
-
message
Returns the value of themessagerecord component.- Returns:
- the value of the
messagerecord component
-