Skip to content

Commit

Permalink
scope down default error
Browse files Browse the repository at this point in the history
  • Loading branch information
eschutho committed Oct 26, 2023
1 parent 906dced commit a917225
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 43 deletions.
14 changes: 2 additions & 12 deletions superset-frontend/packages/superset-ui-core/src/models/Registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export type Listener = (keys: string[]) => void;
export interface RegistryConfig {
name?: string;
overwritePolicy?: OverwritePolicy;
defaultValue?: any;
}

/**
Expand Down Expand Up @@ -89,20 +88,13 @@ export default class Registry<

listeners: Set<Listener>;

defaultValue?: V;

constructor(config: RegistryConfig = {}) {
const {
name = '',
overwritePolicy = OverwritePolicy.ALLOW,
defaultValue,
} = config;
const { name = '', overwritePolicy = OverwritePolicy.ALLOW } = config;
this.name = name;
this.overwritePolicy = overwritePolicy;
this.items = {};
this.promises = {};
this.listeners = new Set();
this.defaultValue = defaultValue;
}

clear() {
Expand Down Expand Up @@ -182,9 +174,7 @@ export default class Registry<

return item.value;
}
if (this.defaultValue) {
return this.defaultValue;
}

return undefined;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,19 +463,4 @@ describe('Registry', () => {
});
});
});
describe('defaultValue', () => {
it('will return the default value if no value is registered', () => {
const registry = new Registry({
defaultValue: 'default',
});
expect(registry.get('a')).toBe('default');
});
it('will return a value if a value is registered', () => {
const registry = new Registry({
defaultValue: 'default',
});
registry.registerValue('a', 'testValue');
expect(registry.get('a')).toBe('testValue');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
import {
Registry,
makeSingleton,
OverwritePolicy,
ErrorTypeEnum,
ErrorLevel,
} from '@superset-ui/core';
import { Registry, makeSingleton, OverwritePolicy } from '@superset-ui/core';
import { ErrorMessageComponent } from './types';

/* Generic error to be returned when the backend returns an error response that is not
* SIP-41 compliant. */
const genericSupersetError = (extra: object) => ({
error_type: ErrorTypeEnum.GENERIC_BACKEND_ERROR,
extra,
level: 'error' as ErrorLevel,
message: 'An error occurred',
});
class ErrorMessageComponentRegistry extends Registry<
ErrorMessageComponent,
ErrorMessageComponent
Expand All @@ -41,7 +27,6 @@ class ErrorMessageComponentRegistry extends Registry<
super({
name: 'ErrorMessageComponent',
overwritePolicy: OverwritePolicy.ALLOW,
defaultValue: genericSupersetError,
});
}
}
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/utils/errorMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

// Error messages used in many places across applications
const COMMON_ERR_MESSAGES = {
SESSION_TIMED_OUT:
Expand Down

0 comments on commit a917225

Please sign in to comment.