Handle JS exceptions in API error logging

When an exception is thrown by our code elsewhere, and caught by the
promise mechanisms, it bubbles up here in the `code` variable, and
`data` is undefined.

Change-Id: I8a0ac49d22d254f353797fc8978871502ae8b9de
This commit is contained in:
Bartosz Dziewoński 2021-11-03 22:21:18 +01:00
parent 6cb595296f
commit d0f8794388

View file

@ -831,12 +831,17 @@ ReplyWidget.prototype.onReplyClick = function () {
widget.errorMessage.$element.insertBefore( widget.replyBodyWidget.$element ); widget.errorMessage.$element.insertBefore( widget.replyBodyWidget.$element );
} }
if ( code instanceof Error ) {
code = 'exception';
}
// Log more precise error codes, mw.Api just gives us 'http' in all of these cases // Log more precise error codes, mw.Api just gives us 'http' in all of these cases
if ( data ) {
if ( data.textStatus === 'timeout' || data.textStatus === 'abort' || data.textStatus === 'parsererror' ) { if ( data.textStatus === 'timeout' || data.textStatus === 'abort' || data.textStatus === 'parsererror' ) {
code = data.textStatus; code = data.textStatus;
} else if ( data.xhr ) { } else if ( data.xhr ) {
code = 'http-' + ( data.xhr.status || 0 ); code = 'http-' + ( data.xhr.status || 0 );
} }
}
logger( { logger( {
action: 'saveFailure', action: 'saveFailure',