-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New: Log preview_error message from Preview #619
Changes from 1 commit
28c1cc2
4fa127c
f8d7960
5bffa55
d8e7a3f
7464a4a
f9463c5
5a299f1
73cb72a
6236dc5
0394df8
82c4e0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,7 @@ import { | |
X_REP_HINT_VIDEO_DASH, | ||
X_REP_HINT_VIDEO_MP4 | ||
} from './constants'; | ||
import { VIEWER_EVENT } from './events'; | ||
import { VIEWER_EVENT, ERROR_CODE } from './events'; | ||
import './Preview.scss'; | ||
|
||
const DEFAULT_DISABLED_VIEWERS = ['Office']; // viewers disabled by default | ||
|
@@ -329,6 +329,10 @@ class Preview extends EventEmitter { | |
/* eslint-disable no-console */ | ||
console.error('[Preview SDK] Tried to cache invalid file: ', file); | ||
/* eslint-enable no-console */ | ||
|
||
const err = new Error(ERROR_CODE.invalidCacheAttempt); | ||
err.data = file; | ||
this.logPreviewError(err); | ||
} | ||
}); | ||
} | ||
|
@@ -531,6 +535,11 @@ class Preview extends EventEmitter { | |
/* eslint-disable no-console */ | ||
console.error(`Error prefetching file ID ${fileId} - ${err}`); | ||
/* eslint-enable no-console */ | ||
|
||
const error = new Error(ERROR_CODE.prefetchFileId); | ||
error.data = fileId; | ||
this.logPreviewError(error); | ||
|
||
return; | ||
} | ||
|
||
|
@@ -992,6 +1001,9 @@ class Preview extends EventEmitter { | |
case VIEWER_EVENT.mediaEndAutoplay: | ||
this.navigateRight(); | ||
break; | ||
case VIEWER_EVENT.error: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we remove this case entirely? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We cannot. This prevents a double error message from being emitted, which would double up on firing off preview_error events. |
||
this.logPreviewError(data.data); | ||
break; | ||
default: | ||
// This includes 'notification', 'preload' and others | ||
this.emit(data.event, data.data); | ||
|
@@ -1152,12 +1164,16 @@ class Preview extends EventEmitter { | |
|
||
// Check if hit the retry limit | ||
if (this.retryCount > RETRY_COUNT) { | ||
let errorCode = ERROR_CODE.retriesExceeded; | ||
let errorMessage = __('error_refresh'); | ||
if (err.response && err.response.status === 429) { | ||
errorCode = ERROR_CODE.rateLimit; | ||
errorMessage = __('error_rate_limit'); | ||
} | ||
|
||
this.triggerError(new Error(errorMessage)); | ||
const error = new Error(errorCode); | ||
error.displayMessage = errorMessage; | ||
this.triggerError(error); | ||
return; | ||
} | ||
|
||
|
@@ -1202,6 +1218,9 @@ class Preview extends EventEmitter { | |
* @return {void} | ||
*/ | ||
triggerError(err) { | ||
// Always log preview errors | ||
this.logPreviewError(err); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there's a chance of double logging here. Above you bound to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aww hell. So, as it is, node requires that you bind to the 'error' event (listener #1), then we listen for it in Does it make sense that we begin listening for errors immediately on viewer creation, and not in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We've confirmed that |
||
|
||
// If preview is closed don't do anything | ||
if (!this.open) { | ||
return; | ||
|
@@ -1226,6 +1245,22 @@ class Preview extends EventEmitter { | |
this.viewer.load(err); | ||
} | ||
|
||
/** | ||
* Message, to any listeners of Preview, that an error has occurred. | ||
* | ||
* @private | ||
* @param {Error} error - The error that occurred. | ||
* @return {void} | ||
*/ | ||
logPreviewError(error) { | ||
const errorMessage = { | ||
error, | ||
data: error.data || '' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How would we access the error type for analytics/debugging? Would that be in the error.message? Would that potentially overwrite a message we would get such as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For logging purposes, we specify our own error codes (see events.js). If we have not thrown the error ourselves, setting the message to one of our error codes, the I'm thinking a single logged event will be as follows:
Note: I just realized I need to update so that we're sending more session related info, per There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we separate that out so that we have Second part sounds good |
||
}; | ||
|
||
this.emit('preview_error', errorMessage); | ||
} | ||
|
||
/** | ||
* Builds a list of required XHR headers. | ||
* | ||
|
@@ -1303,13 +1338,19 @@ class Preview extends EventEmitter { | |
/* eslint-disable no-console */ | ||
console.error(`Error prefetching file ID ${id} - ${err}`); | ||
/* eslint-enable no-console */ | ||
const error = new Error(ERROR_CODE.prefetchFileId); | ||
error.data = id; | ||
this.logPreviewError(error); | ||
}); | ||
}); | ||
}) | ||
.catch(() => { | ||
/* eslint-disable no-console */ | ||
console.error('Error prefetching files'); | ||
/* eslint-enable no-console */ | ||
const error = new Error(ERROR_CODE.prefetchFileId); | ||
error.data = filesToPrefetch; | ||
this.logPreviewError(error); | ||
}); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,26 +106,31 @@ class RepStatus extends EventEmitter { | |
*/ | ||
handleResponse() { | ||
const status = RepStatus.getStatus(this.representation); | ||
let errorCode; | ||
const errCode = RepStatus.getErrorCode(this.representation); | ||
let errorMessage; | ||
let error; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This section changed to allow readable error codes with translated display messages |
||
|
||
switch (status) { | ||
case 'error': | ||
switch (RepStatus.getErrorCode(this.representation)) { | ||
switch (errCode) { | ||
case ERROR_PASSWORD_PROTECTED: | ||
errorCode = __('error_password_protected'); | ||
errorMessage = __('error_password_protected'); | ||
break; | ||
case ERROR_TRY_AGAIN_LATER: | ||
errorCode = __('error_try_again_later'); | ||
errorMessage = __('error_try_again_later'); | ||
break; | ||
case ERROR_UNSUPPORTED_FORMAT: | ||
errorCode = __('error_bad_file'); | ||
errorMessage = __('error_bad_file'); | ||
break; | ||
default: | ||
errorCode = __('error_refresh'); | ||
errorMessage = __('error_refresh'); | ||
break; | ||
} | ||
|
||
this.reject(errorCode); | ||
error = new Error(errCode); | ||
error.displayMessage = errorMessage; | ||
|
||
this.reject(error); | ||
break; | ||
|
||
case STATUS_SUCCESS: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I should abstract away, this functionality?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JustinHoldstock Maybe it would make sense to make a PreviewError which extends Error