Skip to content
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

Merged
merged 4 commits into from
Sep 11, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/i18n/en-US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ error_file_type_unsupported=We're sorry, this file format is not supported.
error_iwork=We're sorry, iWork files are not currently supported.
# Preview error message shown when document loading fails (most likely due to password or watermark)
error_document=We're sorry, the preview didn't load. This document may be protected.
# Preview error message shown when the document is password protected
error_password_protected=We're sorry the preview didn't load. This document is protected.
# Preview error message shown when conversion was unable to process the file at the given time.
error_try_again_later=We're sorry the preview didn't load. Please try again later.
# Preview error message shown when conversion failed due to file contents
error_unsupported_format=We're sorry the preivew didn't load. This file may be corrupted.
Copy link
Contributor

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 to error_corrupted_file?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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'


# Media Preview
# Label for changing speed in media player
Expand Down
38 changes: 36 additions & 2 deletions src/lib/RepStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Copy link
Contributor

Choose a reason for hiding this comment

The 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that it is a little odd but I think that the state is actually the status since the status as we knew it became an object a while back.

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]
*
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions src/lib/viewers/BaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The 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;
};

Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The 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')));
}

/**
Expand Down