@ikaru5/heimdall-controller
Version:
Structure your REST requests by communicating with contracts.
36 lines (30 loc) • 1.12 kB
JavaScript
import ControllerBase from "./controller-base.js"
export default class HeimdallController extends ControllerBase {
static name = "HeimdallController"
static actions = ["csrf", "error", "transportFailed"]
/**
* Handling of initially received token.
* @param {Package} receivedPackage
*/
csrf({ receivedPackage }) {
this._heimdall.csrfToken = receivedPackage.csrfToken
if (undefined !== this._heimdall._afterCSRF) this._heimdall._afterCSRF()
}
/**
* Default handling of transport failures (network down, server unreachable).
* Apps typically subscribe via heimdall.onInbound or listenToAction instead.
* @param {Package} receivedPackage
*/
transportFailed({ receivedPackage }) {
console.error(`Transport failed for ${receivedPackage.payload?.originalReceiver}: ${receivedPackage.payload?.message}`)
}
/**
* Handling of received errors from backend.
* @param {Package} receivedPackage
*/
error({ receivedPackage }) {
let error = "Backend failed to process package:"
let payload = receivedPackage.payload
console.log({error, payload})
}
}