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

Add standard 'localforage' interface for Extensions #116

Merged
merged 7 commits into from
Jul 8, 2020
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
Prev Previous commit
Next Next commit
Fix 'MagicExtensionWarning' log message
  • Loading branch information
smithki committed Jul 7, 2020
commit 34e160b33cb6cebe4feb2805d66710f8277d8c66
73 changes: 40 additions & 33 deletions packages/provider/src/core/sdk-exceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,6 @@ export class MagicSDKError extends Error {
}
}

/**
* This error type is reserved for communicating errors that arise during
* execution of Magic SDK Extension methods. Compare this to the `SDKError`
* type, specifically in context of Extensions.
*/
export class MagicExtensionError<TData = any> extends Error {
__proto__ = Error;

constructor(ext: Extension<string>, public code: string | number, public rawMessage: string, public data: TData) {
super(`Magic Extension Error (${ext.name}): [${code}] ${rawMessage}`);
Object.setPrototypeOf(this, MagicExtensionError.prototype);
}
}

/**
* This error type is reserved for communicating errors that arise during
* execution of Magic SDK Extension methods. Compare this to the `SDKError`
* type, specifically in context of Extensions.
*/
export class MagicExtensionWarning {
public message: string;

constructor(ext: Extension<string>, public code: string | number, public rawMessage: string) {
this.message = `Magic Extension Error (${ext.name}): [${code}] ${rawMessage}`;
}

public log() {
console.warn(this.message);
}
}

/**
* This error type communicates exceptions that occur during execution in the
* Magic `<iframe>` context.
Expand All @@ -73,8 +42,9 @@ export class MagicRPCError extends Error {
}

/**
* In contrast to `SDKError` objects, this "warning" type represents important
* context that does not rise to the level of an exception.
* In contrast to `SDKError` objects, this "warning" type communicates important
* context that does not rise to the level of an exception. These should be
* logged rather than thrown.
*/
export class MagicSDKWarning {
public message: string;
Expand All @@ -83,6 +53,43 @@ export class MagicSDKWarning {
this.message = `Magic SDK Warning: [${code}] ${rawMessage}`;
}

/**
* Logs this warning to the console.
*/
public log() {
console.warn(this.message);
}
}

/**
* This error type is reserved for communicating errors that arise during
* execution of Magic SDK Extension methods. Compare this to the `SDKError`
* type, specifically in context of Extensions.
*/
export class MagicExtensionError<TData = any> extends Error {
__proto__ = Error;

constructor(ext: Extension<string>, public code: string | number, public rawMessage: string, public data: TData) {
super(`Magic Extension Error (${ext.name}): [${code}] ${rawMessage}`);
Object.setPrototypeOf(this, MagicExtensionError.prototype);
}
}

/**
* In contrast to `MagicExtensionError` objects, this "warning" type
* communicates important context that does not rise to the level of an
* exception. These should be logged rather than thrown.
*/
export class MagicExtensionWarning {
public message: string;

constructor(ext: Extension<string>, public code: string | number, public rawMessage: string) {
this.message = `Magic Extension Warning (${ext.name}): [${code}] ${rawMessage}`;
}

/**
* Logs this warning to the console.
*/
public log() {
console.warn(this.message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test('Instantiate `MagicExtensionWarning`', (t) => {
const warning = new MagicExtensionWarning(ext, 'TEST_CODE' as any, 'test message');

t.true(warning instanceof MagicExtensionWarning);
t.is(warning.message, 'Magic Extension Error (test): [TEST_CODE] test message');
t.is(warning.message, 'Magic Extension Warning (test): [TEST_CODE] test message');
t.is(warning.rawMessage, 'test message');
t.is(warning.code, 'TEST_CODE');
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ test('`MagicSDKWarning.log` logs message to `console.warn`', async (t) => {
browserEnv.stub('console.warn', consoleWarningStub);
warning.log();

t.is(consoleWarningStub.args[0][0], 'Magic Extension Error (test): [TEST_CODE] test message');
t.is(consoleWarningStub.args[0][0], 'Magic Extension Warning (test): [TEST_CODE] test message');
});