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,11 +831,16 @@ ReplyWidget.prototype.onReplyClick = function () {
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
if ( data.textStatus === 'timeout' || data.textStatus === 'abort' || data.textStatus === 'parsererror' ) {
code = data.textStatus;
} else if ( data.xhr ) {
code = 'http-' + ( data.xhr.status || 0 );
if ( data ) {
if ( data.textStatus === 'timeout' || data.textStatus === 'abort' || data.textStatus === 'parsererror' ) {
code = data.textStatus;
} else if ( data.xhr ) {
code = 'http-' + ( data.xhr.status || 0 );
}
}
logger( {