var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
/** errorMessage dispatches an event with the error message in it.
* <p>
* Use this function in conjunction with the
* {@linkcode module:elements-sk/error-toast-sk} element.
* </p>
*
* @evt error-sk The event has a detail of the form:
*
* <pre>
* {
* message: "some string",
* duration: (duration in milliseconds),
* }
* </pre>
*
* @param message The value of 'message' is expected to be a string,
* an Object with a field 'message', an Object with a field 'resp'
* that is an instance of window.Response, or an Object.
* @param duration The number of milliseconds the message should be
* displayed.
*
*/
export function errorMessage(message, duration = 10000) {
return __awaiter(this, void 0, void 0, function* () {
if (message.resp instanceof window.Response) {
message = yield message.resp.text();
}
else if (typeof message === 'object') {
message = message.message // for handling Errors {name:String, message:String}
|| JSON.stringify(message); // for everything else
}
const detail = {
message: message,
duration: duration,
};
document.dispatchEvent(new CustomEvent('error-sk', { detail: detail, bubbles: true }));
});
}
;
//# sourceMappingURL=errorMessage.js.map