Skip to content

Commit

Permalink
Revert
Browse files Browse the repository at this point in the history
  • Loading branch information
fortuna committed Jan 22, 2025
1 parent 8cfdfd4 commit 7c0fb81
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
14 changes: 9 additions & 5 deletions client/src/www/app/main.cordova.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@ import {installDefaultMethodChannel, MethodChannel} from './method_channel';
import {VpnApi} from './outline_server_repository/vpn';
import {CordovaVpnApi} from './outline_server_repository/vpn.cordova';
import {OutlinePlatform} from './platform';
import {OUTLINE_PLUGIN_NAME, pluginExec} from './plugin.cordova';
import {
OUTLINE_PLUGIN_NAME,
pluginExec,
pluginExecWithErrorCode,
} from './plugin.cordova';
import {AbstractUpdater} from './updater';
import * as interceptors from './url_interceptor';
import {NoOpVpnInstaller, VpnInstaller} from './vpn_installer';
import {ipcToAppError} from '../model/platform_error';
import {PlatformError} from '../model/platform_error';
import {SentryErrorReporter, Tags} from '../shared/error_reporter';

const hasDeviceSupport = cordova.platformId !== 'browser';
Expand Down Expand Up @@ -72,12 +76,12 @@ class CordovaErrorReporter extends SentryErrorReporter {
}

class CordovaMethodChannel implements MethodChannel {
async invokeMethod(methodName: string, params: string): Promise<string> {
invokeMethod(methodName: string, params: string): Promise<string> {
try {
return await pluginExec('invokeMethod', methodName, params);
return pluginExecWithErrorCode('invokeMethod', methodName, params);
} catch (e) {
console.debug('invokeMethod failed', methodName, e);
throw ipcToAppError(e);
throw PlatformError.parseFrom(e);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/www/app/main.electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {AbstractUpdater} from './updater';
import {UrlInterceptor} from './url_interceptor';
import {VpnInstaller} from './vpn_installer';
import {ErrorCode, OutlinePluginError} from '../model/errors';
import {ipcToAppError} from '../model/platform_error';
import {PlatformError} from '../model/platform_error';
import {
getSentryBrowserIntegrations,
OutlineErrorReporter,
Expand Down Expand Up @@ -137,7 +137,7 @@ class ElectronMethodChannel implements MethodChannel {
params
);
} catch (e) {
throw ipcToAppError(e);
throw PlatformError.parseFrom(e);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/www/app/plugin.cordova.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {ipcToAppError} from '../model/platform_error';
import {PlatformError} from '../model/platform_error';

export const OUTLINE_PLUGIN_NAME = 'OutlinePlugin';

Expand All @@ -30,6 +30,6 @@ export async function pluginExecWithErrorCode<T>(
try {
return await pluginExec<T>(cmd, ...args);
} catch (e) {
throw ipcToAppError(e);
throw PlatformError.parseFrom(e);
}
}
8 changes: 0 additions & 8 deletions client/src/www/model/platform_error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,6 @@ export class PlatformError extends CustomError {
}
}

/**
* ipcToAppError converts an Error returned from the MethodChannel IPC to an application error.
* MethodChannel errors encode its information as a JSON object in the Error message.
*/
export function ipcToAppError(ipcError: Error): CustomError {
return convertRawErrorObjectToPlatformError(JSON.parse(ipcError.message));
}

//////
// Error Code Definitions
// They should be identical to the ones defined in Go's `platerrors` package.
Expand Down

0 comments on commit 7c0fb81

Please sign in to comment.