Record Class ScriptError

java.lang.Object
java.lang.Record
org.omnifaces.cdi.ScriptError
Record Components:
pageURL - The URL of the page where the error occurred, as obtained from window.location.href.
errorMessage - The error message, as obtained from the first argument of window.onerror or the reason of an unhandledrejection event.
errorName - The error type name (e.g. "TypeError", "ReferenceError", "UnhandledRejection"), as obtained from the name property of the Error object, or null if unavailable.
errorStack - The JavaScript stack trace, as obtained from the stack property of the Error object, or null if unavailable.
sourceURL - The URL of the script file where the error originated, as obtained from the second argument of window.onerror, or null for unhandled promise rejections.
lineNumber - The line number in the script where the error occurred, as obtained from the third argument of window.onerror, or null for unhandled promise rejections.
columnNumber - The column number in the script where the error occurred, as obtained from the fourth argument of window.onerror, or null for unhandled promise rejections.
remoteAddr - The remote address of the client, taking proxy headers (X-Forwarded-For etc.) into account.
userAgent - The User-Agent header of the request.
userPrincipal - The name of the authenticated user principal, or null if not authenticated.
All Implemented Interfaces:
Serializable

public record ScriptError(String pageURL, String errorMessage, String errorName, String errorStack, String sourceURL, String lineNumber, String columnNumber, String remoteAddr, String userAgent, String userPrincipal) extends Record implements Serializable

This CDI event will be fired by ScriptErrorHandler when an uncaught JavaScript error or unhandled promise rejection is caught in the client. An application scoped CDI bean can @Observes this event.

For detailed usage instructions, see ScriptErrorHandler javadoc.

Usage

 @ApplicationScoped
 public class ScriptErrorObserver {

     private static final Logger logger = Logger.getLogger(ScriptErrorObserver.class.getName());

     public void onScriptError(@Observes ScriptError error) {
         logger.warning(error.toString());
     }
 }
 
Since:
5.2
Author:
Bauke Scholtz
See Also:
  • Constructor Details

    • ScriptError

      public ScriptError(String pageURL, String errorMessage, String errorName, String errorStack, String sourceURL, String lineNumber, String columnNumber, String remoteAddr, String userAgent, String userPrincipal)
      Creates an instance of a ScriptError record class.
      Parameters:
      pageURL - the value for the pageURL record component
      errorMessage - the value for the errorMessage record component
      errorName - the value for the errorName record component
      errorStack - the value for the errorStack record component
      sourceURL - the value for the sourceURL record component
      lineNumber - the value for the lineNumber record component
      columnNumber - the value for the columnNumber record component
      remoteAddr - the value for the remoteAddr record component
      userAgent - the value for the userAgent record component
      userPrincipal - the value for the userPrincipal record component
  • Method Details

    • 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • pageURL

      public String pageURL()
      Returns the value of the pageURL record component.
      Returns:
      the value of the pageURL record component
    • errorMessage

      public String errorMessage()
      Returns the value of the errorMessage record component.
      Returns:
      the value of the errorMessage record component
    • errorName

      public String errorName()
      Returns the value of the errorName record component.
      Returns:
      the value of the errorName record component
    • errorStack

      public String errorStack()
      Returns the value of the errorStack record component.
      Returns:
      the value of the errorStack record component
    • sourceURL

      public String sourceURL()
      Returns the value of the sourceURL record component.
      Returns:
      the value of the sourceURL record component
    • lineNumber

      public String lineNumber()
      Returns the value of the lineNumber record component.
      Returns:
      the value of the lineNumber record component
    • columnNumber

      public String columnNumber()
      Returns the value of the columnNumber record component.
      Returns:
      the value of the columnNumber record component
    • remoteAddr

      public String remoteAddr()
      Returns the value of the remoteAddr record component.
      Returns:
      the value of the remoteAddr record component
    • userAgent

      public String userAgent()
      Returns the value of the userAgent record component.
      Returns:
      the value of the userAgent record component
    • userPrincipal

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