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 call errorCode() instead of comparing this directly
message - 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:
GeolocationOutcome, GeolocationResult, Serializable

public record GeolocationError(int code, String message) extends Record implements GeolocationOutcome
A failed location reading: the request did not produce a GeolocationPosition.

This is one of the three possible values of a GeolocationWatcher.valueSignal() signal, and the value passed to the error callback of Geolocation.getPosition. Typical application code switches on errorCode() to react to the specific reason:

 ui.getGeolocation().getPosition(pos -> showNearest(pos), 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("Could not read your location.");
     }
 });
 
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 Details

    • GeolocationError

      public GeolocationError(int code, String message)
      Creates an instance of a GeolocationError record class.
      Parameters:
      code - the value for the code record component
      message - the value for the message record component
  • Method Details

    • errorCode

      public GeolocationErrorCode errorCode()
      Returns the error reason as a typed enum suitable for exhaustive switch. Returns GeolocationErrorCode.UNKNOWN if the browser reports a numeric code this version of Flow does not recognise.
      Returns:
      the matching GeolocationErrorCode, or GeolocationErrorCode.UNKNOWN when the raw code() is not one of the known values
    • toString

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • code

      public int code()
      Returns the value of the code record component.
      Returns:
      the value of the code record component
    • message

      public String message()
      Returns the value of the message record component.
      Returns:
      the value of the message record component