feat: 🎸 add logging to notifyError decorator (#2694)
* feat: 🎸 add logging to notifyError decorator ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-16334 * refactor: 💡 update reference to global electronLog ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-16334 * refactor: 💡 update __electronLog global references ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-16334 * refactor: 💡 add log to other cluster URL actions ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-16334 * refactor: 💡 update how we trigger electron log in notifyError ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-16334 * refactor: 💡 minor log change ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-16334
This commit is contained in:
1 parent
e25a854d24
commit
750cc1ecae
9 files changed
+32
-6
No files matched your search
@@ -3,13 +3,14 @@
|
||||
* SPDX-License-Identifier: BUSL-1.1
|
||||
*/
|
||||
|
||||
/* global __electronLog */
|
||||
import { inject as service } from '@ember/service';
|
||||
import { getOwner, setOwner } from '@ember/application';
|
||||
import { generateMQLExpression } from '../utils/mql-query';
|
||||
import { paginateResults } from '../utils/paginate-results';
|
||||
import { underscore } from '@ember/string';
|
||||
|
||||
const { __electronLog } = globalThis;
|
||||
|
||||
/**
|
||||
* Not all types are yet supported by the cache daemon so we'll
|
||||
* just whitelist the ones we need to start with. Keys are the resource
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
import { getOwner } from '@ember/application';
|
||||
|
||||
const { __electronLog } = globalThis;
|
||||
|
||||
/**
|
||||
* Decorates a method and, if the method does not error, shows a success
|
||||
* notification via the notify service. The text of the notification is derived
|
||||
@@ -50,10 +52,17 @@ export function notifySuccess(notification) {
|
||||
*
|
||||
* @param {string|function} notification
|
||||
* @param {object} options
|
||||
* @param {object} options.sticky - defaults to true, whether or not to persist
|
||||
* @param {boolean} options.sticky - defaults to true, whether or not to persist
|
||||
* the notification until user dismissal
|
||||
* @param {object} options.catch - defaults to false, whether or not to catch
|
||||
* @param {boolean} options.catch - defaults to false, whether or not to catch
|
||||
* and squelch the error
|
||||
* @param {object} options.log - defaults to undefined, object with unique
|
||||
* information about the error to send to our
|
||||
* electron logging service
|
||||
* @param {string} options.log.origin - defaults to undefined, the origin that
|
||||
* triggered the error
|
||||
* @param {string} options.log.level - defaults to undefined, the log level that
|
||||
* our electron logging service should use
|
||||
*/
|
||||
export function notifyError(
|
||||
notification,
|
||||
@@ -69,6 +78,10 @@ export function notifyError(
|
||||
try {
|
||||
return await method.apply(this, arguments);
|
||||
} catch (error) {
|
||||
if (options.log) {
|
||||
const { origin, level = 'error' } = options.log;
|
||||
__electronLog?.[level](`${origin}:`, error.message);
|
||||
}
|
||||
const candidateKey =
|
||||
typeof notification === 'function'
|
||||
? notification.apply(this, [error])
|
||||
|
||||
@@ -25,7 +25,6 @@ module.exports = {
|
||||
env: {
|
||||
browser: true,
|
||||
},
|
||||
globals: { __electronLog: 'true' },
|
||||
rules: {
|
||||
'ember/no-get': 'off',
|
||||
'ember/no-get-with-default': 'off',
|
||||
|
||||
@@ -26,6 +26,7 @@ export default class ClusterUrlController extends Controller {
|
||||
@loading
|
||||
@notifyError(() => 'errors.cluster-url-verification-failed.description', {
|
||||
catch: true,
|
||||
log: { origin: 'setClusterUrl' },
|
||||
})
|
||||
async setClusterUrl(clusterUrl) {
|
||||
await this.clusterUrlService.setClusterUrl(clusterUrl);
|
||||
|
||||
@@ -29,7 +29,10 @@ export default class ApplicationRoute extends Route {
|
||||
* reported by the main process. If they differ, update the main process
|
||||
* clusterUrl so that the renderer's CSP can be rewritten to allow requests.
|
||||
*/
|
||||
@notifyError(({ message }) => message, { catch: true })
|
||||
@notifyError(({ message }) => message, {
|
||||
catch: true,
|
||||
log: { origin: 'ApplicationRoute:beforeModel' },
|
||||
})
|
||||
async beforeModel() {
|
||||
this.intl.setLocale(['en-us']);
|
||||
await this.session.setup();
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
import Route from '@ember/routing/route';
|
||||
import { inject as service } from '@ember/service';
|
||||
|
||||
const { __electronLog } = globalThis;
|
||||
|
||||
/**
|
||||
* TODO: This route is now vestigial. Desktop does not provide project-based
|
||||
* navigation. This route formerly provided a way to aggregate
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
import Route from '@ember/routing/route';
|
||||
import { inject as service } from '@ember/service';
|
||||
|
||||
const { __electronLog } = globalThis;
|
||||
|
||||
export default class ScopesScopeProjectsSessionsSessionRoute extends Route {
|
||||
// =services
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ import {
|
||||
} from 'api/models/session';
|
||||
import { action } from '@ember/object';
|
||||
|
||||
const { __electronLog } = globalThis;
|
||||
|
||||
export default class ScopesScopeProjectsTargetsIndexRoute extends Route {
|
||||
// =services
|
||||
|
||||
|
||||
@@ -88,7 +88,10 @@ export default class ClusterUrlService extends Service {
|
||||
/**
|
||||
* Resets the clusterUrl.
|
||||
*/
|
||||
@notifyError(({ message }) => message, { catch: true })
|
||||
@notifyError(({ message }) => message, {
|
||||
catch: true,
|
||||
log: { origin: 'resetClusterUrl' },
|
||||
})
|
||||
async resetClusterUrl() {
|
||||
this.rendererClusterUrl = null;
|
||||
await this.ipc.invoke('resetClusterUrl');
|
||||
|
||||
Reference in new issue
Block a user