UnhandledRejection: Difference between revisions
(Created page with "{{ClientsideJsFunction}} {{JSContainer| <syntaxhighlight lang="javascript"> mp.events.add('unhandledRejection', (promise, error) => { //do what you want }); </syntaxhighlight> }} ==See also== {{Player_events_clientside}}") |
(example of canceling default message box) |
||
| Line 1: | Line 1: | ||
{{ClientsideJsFunction}} | {{ClientsideJsFunction}} | ||
{{JSContainer| | {{JSContainer| | ||
<syntaxhighlight lang=" | {{Parameters}} | ||
* '''promise''': Promise that was rejected and not handled, it is of '''Promise<any>''' type. | |||
* '''error''': Error of the promise that was rejected, it is of '''any''' type. | |||
{{Example}} | |||
The example below cancels the default error message box on client unhandled promise rejection and prints to the F11 console instead. | |||
<syntaxhighlight lang="JavaScript"> | |||
mp.events.add('unhandledRejection', (promise, error) => { | mp.events.add('unhandledRejection', (promise, error) => { | ||
// | // Print the message to F11 console instead or forward to the server for logging | ||
mp.console.logError(`[unhandledRejection]: ${JSON.stringify(promise)} ${error}`); | |||
// Cancel the event to prevent default error message box | |||
return true; | |||
}); | }); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 18:30, 3 September 2025
Client-Side Function
JavaScript Syntax
Parameters
- promise: Promise that was rejected and not handled, it is of Promise<any> type.
- error: Error of the promise that was rejected, it is of any type.
Example
The example below cancels the default error message box on client unhandled promise rejection and prints to the F11 console instead.
mp.events.add('unhandledRejection', (promise, error) => {
// Print the message to F11 console instead or forward to the server for logging
mp.console.logError(`[unhandledRejection]: ${JSON.stringify(promise)} ${error}`);
// Cancel the event to prevent default error message box
return true;
});
See also
Browser
Checkpoints
Colshapes
Console
Common
- click
- playerChat
- playerCommand
- playerDeath
- playerJoin
- playerQuit
- playerReady
- playerResurrect
- playerRuleTriggered
- playerSpawn
- playerWeaponShot
- addDataHandler
- dummyEntityCreated
- dummyEntityDestroyed
- entityControllerChange
- replayEditorRequest
- pauseMenuItemSelect
- pauseMenuItemChange