Skip to content

Commit

Permalink
send schema refresh errors as part of API response
Browse files Browse the repository at this point in the history
  • Loading branch information
Omer Lachish committed Apr 30, 2020
1 parent c38d826 commit bc69c03
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
4 changes: 3 additions & 1 deletion client/app/pages/queries/hooks/useDataSourceSchema.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { reduce } from "lodash";
import { useCallback, useEffect, useRef, useState, useMemo } from "react";
import { axios } from "@/services/axios";
import DataSource from "@/services/data-source";
import DataSource, { SCHEMA_NOT_SUPPORTED } from "@/services/data-source";
import notification from "@/services/notification";

function sleep(ms) {
Expand All @@ -20,6 +20,8 @@ function getSchema(dataSource, refresh = undefined) {
return fetchSchemaFromJob(data);
} else if (data.job.status === 3) {
return data.job.result;
} else if (data.job.status === 4 && data.job.error.code === SCHEMA_NOT_SUPPORTED) {
return [];
} else {
return Promise.reject(new Error(data.job.error));
}
Expand Down
2 changes: 2 additions & 0 deletions client/app/services/data-source.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { axios } from "@/services/axios";

export const SCHEMA_NOT_SUPPORTED = 1;
export const SCHEMA_LOAD_ERROR = 2;
export const IMG_ROOT = "/static/images/db-logos";

const DataSource = {
Expand Down
3 changes: 3 additions & 0 deletions redash/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ def serialize_job(job):
elif isinstance(job.result, Exception):
error = str(job.result)
status = 4
elif isinstance(job.result, dict) and "error" in job.result:
error = job.result["error"]
status = 4
else:
error = ""
result = query_result_id = job.result
Expand Down
11 changes: 8 additions & 3 deletions redash/tasks/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,14 @@ def get_schema(data_source_id, refresh):
data_source = models.DataSource.get_by_id(data_source_id)
return data_source.query_runner.get_schema(refresh)
except NotSupported:
return []
except Exception as e:
return e
return {
"error": {
"code": 1,
"message": "Data source type does not support retrieving schema",
}
}
except Exception:
return {"error": {"code": 2, "message": "Error retrieving schema."}}


def sync_user_details():
Expand Down

0 comments on commit bc69c03

Please sign in to comment.