-
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: More specific error messages from conversion #378
Changes from 1 commit
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 |
---|---|---|
|
@@ -4,20 +4,38 @@ import { STATUS_SUCCESS, STATUS_VIEWABLE } from './constants'; | |
|
||
const STATUS_UPDATE_INTERVAL_MS = 2000; | ||
|
||
const ERROR_PASSWORD_PROTECTED = 'error_password_protected'; | ||
const ERROR_TRY_AGAIN_LATER = 'error_try_again_later'; | ||
const ERROR_UNSUPPORTED_FORMAT = 'error_unsupported_format'; | ||
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. See above comment |
||
const ERROR_REFRESH = 'error_refesh'; | ||
|
||
class RepStatus extends EventEmitter { | ||
/** | ||
* Gets the status out of represenation | ||
* | ||
* @public | ||
* @param {Object} representation - representation object | ||
* @return {string} rep status instance | ||
* @return {string} rep status state | ||
*/ | ||
static getStatus(representation) { | ||
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. Not sure this makes sense to be called getStatus() anymore since it's technically returning the state of the RepStatus rather than the status itself. Might just be a nitpick but thoughts? 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. Agreed that it is a little odd but I think that the |
||
let { status } = representation; | ||
status = typeof status === 'object' ? status.state : representation.temp_status.state; | ||
return status; | ||
} | ||
|
||
/** | ||
* Gets the error code out of the representation | ||
* | ||
* @public | ||
* @param {Object} representation - representation object | ||
* @return {string} rep error code | ||
*/ | ||
static getErrorCode(representation) { | ||
const { status } = representation; | ||
const code = typeof status === 'object' ? status.code : representation.temp_status.code; | ||
return code; | ||
} | ||
|
||
/** | ||
* [constructor] | ||
* | ||
|
@@ -89,9 +107,25 @@ class RepStatus extends EventEmitter { | |
*/ | ||
handleResponse() { | ||
const status = RepStatus.getStatus(this.representation); | ||
let errorCode; | ||
switch (status) { | ||
case 'error': | ||
this.reject(); | ||
switch (RepStatus.getErrorCode(this.representation)) { | ||
case ERROR_PASSWORD_PROTECTED: | ||
errorCode = __(ERROR_PASSWORD_PROTECTED); | ||
break; | ||
case ERROR_TRY_AGAIN_LATER: | ||
errorCode = __(ERROR_TRY_AGAIN_LATER); | ||
break; | ||
case ERROR_UNSUPPORTED_FORMAT: | ||
errorCode = __(ERROR_UNSUPPORTED_FORMAT); | ||
break; | ||
default: | ||
errorCode = __(ERROR_REFRESH); | ||
break; | ||
} | ||
|
||
this.reject(errorCode); | ||
break; | ||
|
||
case STATUS_SUCCESS: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -229,13 +229,13 @@ class BaseViewer extends EventEmitter { | |
}; | ||
|
||
/** | ||
* Emits an error when an asset (static or representation) fails to load. | ||
* triggers an error when an asset (static or representation) fails to load. | ||
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. Capitalize "triggers" |
||
* | ||
* @emits error | ||
* @param {string} [err] - Optional error message | ||
* @return {void} | ||
*/ | ||
handleAssetError = () => { | ||
this.triggerError(); | ||
handleAssetError = (err) => { | ||
this.triggerError(err); | ||
this.destroyed = true; | ||
}; | ||
|
||
|
@@ -244,11 +244,11 @@ class BaseViewer extends EventEmitter { | |
* | ||
* @protected | ||
* @emits error | ||
* @param {Error} [err] - Optional error with message | ||
* @param {Error|string} [err] - Optional error or stringwith message | ||
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. or string with |
||
* @return {void} | ||
*/ | ||
triggerError(err) { | ||
this.emit('error', err instanceof Error ? err : new Error(__('error_refresh'))); | ||
this.emit('error', err instanceof Error ? err : new Error(err || __('error_refresh'))); | ||
} | ||
|
||
/** | ||
|
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.
Is this supposed to be
error_unsupported_format
? Or should it be changed toerror_corrupted_file
?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.
good point. Harris is going to look into all of the cases that cause this error to fire.
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.
This applies to a variety of situations including both unsupported files and corrupted ones. Technically a corrupted file is unsupported so that's slightly more of an umbrella term?
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.
Also, spelling: 'preview' not 'preivew'