Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
85811413
Commit
85811413
authored
8 years ago
by
Lewis Liu
Browse files
Options
Downloads
Patches
Plain Diff
Refactored fetch error handling into function, added tests
parent
7a723299
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontend/src/metabase/dashboard/dashboard.js
+10
-7
10 additions, 7 deletions
frontend/src/metabase/dashboard/dashboard.js
frontend/test/unit/dashboard/dashboard.spec.js
+32
-0
32 additions, 0 deletions
frontend/test/unit/dashboard/dashboard.spec.js
with
42 additions
and
7 deletions
frontend/src/metabase/dashboard/dashboard.js
+
10
−
7
View file @
85811413
...
...
@@ -113,6 +113,15 @@ const updateDashcardId = createAction(UPDATE_DASHCARD_ID, (oldDashcardId, newDas
const
CLEAR_CARD_DATA
=
"
CLEAR_CARD_DATA
"
;
export
const
clearCardData
=
createAction
(
CLEAR_CARD_DATA
,
(
cardId
,
dashcardId
)
=>
({
cardId
,
dashcardId
}));
export
async
function
fetchDataOrError
(
dataPromise
)
{
try
{
return
await
dataPromise
;
}
catch
(
error
)
{
return
{
error
};
}
}
export
const
fetchCardData
=
createThunkAction
(
FETCH_CARD_DATA
,
function
(
card
,
dashcard
,
clearExisting
=
false
)
{
return
async
function
(
dispatch
,
getState
)
{
if
(
clearExisting
)
{
...
...
@@ -152,13 +161,7 @@ export const fetchCardData = createThunkAction(FETCH_CARD_DATA, function(card, d
}
},
DATASET_SLOW_TIMEOUT
);
try
{
result
=
await
MetabaseApi
.
dataset
(
datasetQuery
);
}
catch
(
error
)
{
result
=
{
error
};
}
result
=
await
fetchDataOrError
(
Promise
.
reject
({
data
:
{
message
:
'
test
'
}}));
clearTimeout
(
slowCardTimer
);
return
{
dashcard_id
:
dashcard
.
id
,
card_id
:
card
.
id
,
result
};
...
...
This diff is collapsed.
Click to expand it.
frontend/test/unit/dashboard/dashboard.spec.js
0 → 100644
+
32
−
0
View file @
85811413
import
{
fetchDataOrError
}
from
'
metabase/dashboard/dashboard
'
;
describe
(
"
Dashboard
"
,
()
=>
{
describe
(
"
fetchDataOrError()
"
,
()
=>
{
it
(
"
should return data on successful fetch
"
,
async
()
=>
{
const
data
=
{
series
:
[
1
,
2
,
3
]
};
const
successfulFetch
=
Promise
.
resolve
(
data
);
const
result
=
await
fetchDataOrError
(
successfulFetch
);
expect
(
result
.
error
).
toBeUndefined
();
expect
(
result
).
toEqual
(
data
);
});
it
(
"
should return map with error key on failed fetch
"
,
async
()
=>
{
const
error
=
{
status
:
504
,
statusText
:
"
GATEWAY_TIMEOUT
"
,
data
:
{
message
:
"
Failed to load resource: the server responded with a status of 504 (GATEWAY_TIMEOUT)
"
}
};
const
failedFetch
=
Promise
.
reject
(
error
);
const
result
=
await
fetchDataOrError
(
failedFetch
);
expect
(
result
.
error
).
toEqual
(
error
);
});
});
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment