Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Nov 26, 2024
1 parent b311536 commit 8822342
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 33 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"charts"
],
"license": "MIT",
"version": "0.0.35",
"version": "0.0.37",
"type": "module",
"main": "./dist/galaxy-charts.umd.cjs",
"module": "./dist/galaxy-charts.js",
Expand All @@ -30,7 +30,7 @@
"build:types": "vue-tsc --declaration --emitDeclarationOnly --outDir dist",
"postbuild": "npm run build:types",
"preview": "vite preview",
"prettier": "prettier --write 'package.json' '*.js' 'src/**/*.js' 'src/**/*.vue'",
"prettier": "prettier --write 'package.json' '*.js' 'src/**/*.js' 'src/**/*.ts' 'src/**/*.vue'",
"test": "vitest"
},
"devDependencies": {
Expand Down
6 changes: 4 additions & 2 deletions src/Plugin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ const viewport = ref(null);
const columnsStore = useColumnsStore();
const columnsList = ref();
async function render() {
/** Place your render function here! */
const columnsList = await columnsStore.fetchColumns(props.datasetId, props.tracks, ["x", "y", "z"]);
console.log(columnsList);
columnsList.value = await columnsStore.fetchColumns(props.datasetId, props.tracks, ["x", "y", "z"]);
}
function onSave() {
Expand Down Expand Up @@ -52,6 +53,7 @@ watch(
<div class="bg-gray-600 text-white rounded-lg p-2">
<pre class="p-2">Settings: {{ settings }}</pre>
<pre class="p-2">Tracks: {{ tracks }}</pre>
<pre>{{ columnsList }}</pre>
</div>
</div>
</template>
8 changes: 6 additions & 2 deletions src/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ async function fetchApi(path: string, options: RequestInit): Promise<{ data: any
headers: { "Content-Type": "application/json" },
...options,
});
const data = await response.json();
return { data, response };
if (response.ok) {
const data = await response.json();
return { data, response };
} else {
rethrowSimple(response);
}
} catch (err) {
rethrowSimple(err);
}
Expand Down
20 changes: 9 additions & 11 deletions src/api/datasets.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { GalaxyApi } from "@/api/client";
import { rethrowSimple } from "@/utilities/simpleError";

export async function datasetsGetColumns(datasetId: string, columnList: string[]): Promise<any[][] | undefined> {
try {
const params = new URLSearchParams({
data_type: "raw_data",
provider: "dataset-column",
indeces: columnList.toString(),
}).toString();
const params = new URLSearchParams({
data_type: "raw_data",
provider: "dataset-column",
indeces: columnList.toString(),
}).toString();

try {
const { data } = await GalaxyApi().GET(`/api/datasets/${datasetId}?${params}`);
const columnLength = columnList.length;
const results: any[][] = new Array(columnLength).fill(null).map(() => []);

for (const row of data.data) {
for (const j in row) {
const index = Number(j);
Expand All @@ -21,11 +21,9 @@ export async function datasetsGetColumns(datasetId: string, columnList: string[]
}
}
}

return results;
} catch (err) {
console.error(err);
return undefined;
} catch (e) {
rethrowSimple(e);
}
}

Expand Down
17 changes: 13 additions & 4 deletions src/api/visualizations.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { rethrowSimple } from "@/utilities/simpleError";
import { GalaxyApi } from "@/api/client";
import { InputValuesType } from "@/types"
import { InputValuesType } from "@/types";
import { rethrowSimple } from "@/utilities/simpleError";

interface VisualizationConfig {
dataset_id: string;
settings: InputValuesType;
tracks: Array<InputValuesType>;
}

export async function visualizationsCreate(type: string, title: string, config: VisualizationConfig): Promise<string | undefined> {
export async function visualizationsCreate(
type: string,
title: string,
config: VisualizationConfig,
): Promise<string | undefined> {
try {
const { data } = await GalaxyApi().POST("/api/visualizations", {
type,
Expand All @@ -21,7 +25,12 @@ export async function visualizationsCreate(type: string, title: string, config:
}
}

export async function visualizationsSave(type: string, id: string | null, title: string, config: VisualizationConfig): Promise<string | undefined> {
export async function visualizationsSave(
type: string,
id: string | null,
title: string,
config: VisualizationConfig,
): Promise<string | undefined> {
try {
if (id) {
await visualizationsUpdate(id, title, config);
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ export interface PluginConfigType {

export interface PluginIncomingType {
root?: string;
visualization_config?: PluginConfigType,
visualization_config?: PluginConfigType;
visualization_id?: string;
visualization_plugin?: PluginType,
visualization_plugin?: PluginType;
visualization_title?: string;
}

Expand Down
7 changes: 1 addition & 6 deletions src/utilities/parseColumns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ interface Column {
value: string;
}

export function parseColumns(
dataset: Dataset,
isAuto: boolean,
isText: boolean,
isNumber: boolean
): Array<Column> {
export function parseColumns(dataset: Dataset, isAuto: boolean, isText: boolean, isNumber: boolean): Array<Column> {
const columns: Array<Column> = [];

if (isAuto) {
Expand Down
5 changes: 1 addition & 4 deletions src/utilities/parsePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ interface ParsedPlugin {
}

// Parse plugin either from incoming object or XML
export async function parsePlugin(
plugin: PluginType,
config: PluginConfigType = {}
): Promise<ParsedPlugin> {
export async function parsePlugin(plugin: PluginType, config: PluginConfigType = {}): Promise<ParsedPlugin> {
const settings = parseValues(plugin.settings, config.settings);
const specs = plugin.specs;
const tracks = parseTracks(plugin.tracks, config.tracks);
Expand Down
6 changes: 6 additions & 0 deletions src/utilities/sleep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const WAITTIME = 2000;

/** Wait helper */
export function sleep(wt = WAITTIME) {
return new Promise((resolve) => setTimeout(resolve, wt));
}

0 comments on commit 8822342

Please sign in to comment.