mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 04:31:36 +08:00

* Initial schema - Add types based off of current frontend * Rename and field-level comments * Update report and regenerate files * Rename frontend Azure folder - Doing this for consistency and to ensure code-generation works - Update betterer results due to file renames * Remove default and add back enum vals that I deleted * Set workspace prop as optional * Replace template variable types * Connect frontend query types - Keep properties optional for now to avoid major changes - Rename AzureMetricResource - Correctly use ResultFormat * Add TSVeneer decorator * Update schema * Update type * Update CODEOWNERS * Fix gen-cue issue * Fix backend test * Fix e2e test * Update code coverage * Remove references to old Azure Monitor path * Review * Regen files
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { isValidElement } from 'react';
|
|
|
|
import { AzureMonitorErrorish } from '../types';
|
|
|
|
export function messageFromElement(error: AzureMonitorErrorish): AzureMonitorErrorish | undefined {
|
|
if (isValidElement(error)) {
|
|
return error;
|
|
} else {
|
|
return messageFromError(error);
|
|
}
|
|
}
|
|
|
|
export default function messageFromError(error: any): string | undefined {
|
|
if (!error || typeof error !== 'object') {
|
|
return undefined;
|
|
}
|
|
|
|
if (typeof error.message === 'string') {
|
|
return error.message;
|
|
}
|
|
|
|
if (typeof error.data?.error?.message === 'string') {
|
|
return error.data.error.message;
|
|
}
|
|
|
|
// Copied from the old Angular code - this might be checking for errors in places
|
|
// that the new code just doesnt use.
|
|
// As new error objects are discovered they should be added to the above code, rather
|
|
// than below
|
|
const maybeAMessage =
|
|
error.error?.data?.error?.innererror?.innererror?.message ||
|
|
error.error?.data?.error?.innererror?.message ||
|
|
error.error?.data?.error?.message ||
|
|
error.error?.data?.message ||
|
|
error.data?.message ||
|
|
error;
|
|
|
|
if (typeof maybeAMessage === 'string') {
|
|
return maybeAMessage;
|
|
} else if (maybeAMessage && maybeAMessage.toString) {
|
|
return maybeAMessage.toString();
|
|
}
|
|
|
|
return undefined;
|
|
}
|