mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 14:22:20 +08:00

* start on tokens * more error messages * more handling * rephrased with suggestions from Daniel * separate gms parse method * use translation * refactor initial idea to use error obj * use error dto result * handle gms client * clean logs and comments * fix tests * tests for gms * test and lint * lint * one more handling from gms * typing in fe * use error interface * use validation error * remove unused gms error * use errorlib and helper function in fe * regen api * use same error util * one more error to handle
20 lines
686 B
TypeScript
20 lines
686 B
TypeScript
import { isFetchError } from '@grafana/runtime';
|
|
|
|
// TODO: candidate to hoist and share
|
|
export function maybeAPIError(err: unknown) {
|
|
if (!isFetchError<unknown>(err) || typeof err.data !== 'object' || !err.data) {
|
|
return null;
|
|
}
|
|
|
|
const data = err?.data;
|
|
const message = 'message' in data && typeof data.message === 'string' ? data.message : null;
|
|
const messageId = 'messageId' in data && typeof data.messageId === 'string' ? data.messageId : null;
|
|
const statusCode = 'statusCode' in data && typeof data.statusCode === 'number' ? data.statusCode : null;
|
|
|
|
if (!message || !messageId || !statusCode) {
|
|
return null;
|
|
}
|
|
|
|
return { message, messageId, statusCode };
|
|
}
|