JsErrors
in package
Utilities for frontend error logging.
Register this using JsErrors::needs() in your skin/sprout_load.php.
Alternatively, one can configure this manually (twig example):
<script src="ROOT/media/js/kbtrace.min.js"></script>
<script>
kbtrace.config({{ sprout.errors.config|json_encode|raw }});
kbtrace.register();
</script>
Table of Contents
Constants
- API_PATH : mixed = '_errors/log'
Methods
- authorize() : bool
- Verify the request is valid.
- formatError() : string
- Format a JS error + stack into a string.
- formatFrame() : string
- Format a JS stack frame into a string.
- getConfig() : array<string|int, mixed>
- Get a JS tracing config to use with `kbtrace.config()`.
- getSiteToken() : string
- Get the tracing auth token.
- getSiteUid() : string
- Get the tracing UID.
- needs() : void
- Register the needs for the JS error handler.
- parseFilename() : string|null
- Clean up URL paths so we can compare them against a source map.
- getTokenPayload() : array<string|int, mixed>|null
- This is the basis for generating the auth token.
Constants
API_PATH
public
mixed
API_PATH
= '_errors/log'
Methods
authorize()
Verify the request is valid.
public
static authorize() : bool
Return values
boolformatError()
Format a JS error + stack into a string.
public
static formatError(array<string|int, mixed> $error[, bool $cleanPaths = false ]) : string
A formatted stack-trace, as defined at: https://v8.dev/docs/stack-trace-api
Parameters
- $error : array<string|int, mixed>
- $cleanPaths : bool = false
Return values
stringformatFrame()
Format a JS stack frame into a string.
public
static formatFrame(array<string|int, mixed> $frame[, bool $cleanPath = false ]) : string
A formatted stack-trace, as defined at: https://v8.dev/docs/stack-trace-api
Parameters
- $frame : array<string|int, mixed>
- $cleanPath : bool = false
Return values
stringgetConfig()
Get a JS tracing config to use with `kbtrace.config()`.
public
static getConfig() : array<string|int, mixed>
Return values
array<string|int, mixed>getSiteToken()
Get the tracing auth token.
public
static getSiteToken() : string
This is an HMAC signature (SHA1) made against the Sprout security key (database.server_key).
Return values
stringgetSiteUid()
Get the tracing UID.
public
static getSiteUid() : string
This is namespaced to the site URL so it's consistent but still unique for each hostname.
Return values
stringneeds()
Register the needs for the JS error handler.
public
static needs() : void
This uses the bootstrapping feature and the JS library will configure itself.
Best place this in the skin/sprout_load.php.
parseFilename()
Clean up URL paths so we can compare them against a source map.
public
static parseFilename(string $filename) : string|null
Parameters
- $filename : string
Return values
string|nullgetTokenPayload()
This is the basis for generating the auth token.
protected
static getTokenPayload() : array<string|int, mixed>|null
This payload must be reasonably predictable (for us). If the payload changes between issuing the token to the JS library and receiving an error event - it will be invalid.
The payload will change if:
- the session expires (usually ~30 minutes without a refresh)
- the IP address changes (roaming networks)
- the base URL changes (somehow)
These are acceptable conditions for the authentication to re-generate.
The payload is null if there is no session, such as CLI environments.