Skip to content

Commit 1b76fab

Browse files
Aiden Keatingdavid-martin
Aiden Keating
authored andcommitted
Display error during thread init
1 parent 930d564 commit 1b76fab

File tree

6 files changed

+56
-18
lines changed

6 files changed

+56
-18
lines changed

Diff for: gitea_client.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ exports.createRepoForUser = (username, repo) => {
124124
const normalizedUser = normalizeUser(username);
125125
return new Promise((resolve, reject) => {
126126
if (!GITEA_HOST || !GITEA_TOKEN) {
127-
return reject(new Error('Gitea not installed'));
127+
return reject(new Error('Gitea is not configured. Repositories cannot be created.'));
128128
}
129129

130130
if (!repo || !repo.repoName) {
@@ -154,4 +154,4 @@ exports.createRepoForUser = (username, repo) => {
154154
.catch(reject);
155155
});
156156
});
157-
};
157+
};

Diff for: server.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,22 @@ app.post('/initThread', fetchOpenshiftUser, (req, res) => {
3535

3636
// Return success in mock mode without actually creating any repositories
3737
if (!process.env.OPENSHIFT_HOST) {
38-
return res.sendStatus(200);
38+
console.warn('OPENSHIFT_HOST not set. Skipping thread initialization.');
39+
res.sendStatus(200);
40+
return;
3941
}
4042

41-
if (repos && repos.length > 0) {
42-
return Promise.all(repos.map(repo => giteaClient.createRepoForUser(openshiftUser, repo)))
43-
.then(() => res.sendStatus(200))
44-
.catch(err => {
45-
console.error(`Error creating repositories: ${err}`);
46-
return res.sendStatus(500);
47-
});
48-
} else {
49-
return res.sendStatus(200);
43+
if (!repos || repos.length === 0) {
44+
res.sendStatus(200);
45+
return;
5046
}
47+
48+
return Promise.all(repos.map(repo => giteaClient.createRepoForUser(openshiftUser, repo)))
49+
.then(() => res.sendStatus(200))
50+
.catch(err => {
51+
console.error(`Error creating repositories: ${err}`);
52+
return res.status(500).json({ error: err.message });
53+
});
5154
});
5255

5356
// Dynamic configuration for openshift API calls

Diff for: src/redux/actions/threadActions.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { threadTypes } from '../constants';
22
import { threadServices } from '../../services';
3+
import { PENDING_ACTION, FULFILLED_ACTION, REJECTED_ACTION } from '../helpers';
34

45
const getThread = (language, id) => ({
56
type: threadTypes.GET_THREAD,
@@ -16,9 +17,31 @@ const initCustomThread = id => ({
1617
payload: threadServices.initCustomThread(id)
1718
});
1819

20+
const initCustomThreadPending = () => ({
21+
type: PENDING_ACTION(threadTypes.INIT_THREAD)
22+
});
23+
24+
const initCustomThreadSuccess = payload => ({
25+
type: FULFILLED_ACTION(threadTypes.INIT_THREAD),
26+
payload
27+
});
28+
29+
const initCustomThreadFailure = error => ({
30+
type: REJECTED_ACTION(threadTypes.INIT_THREAD),
31+
payload: { error }
32+
});
33+
1934
const updateThreadProgress = (id, progress) => ({
2035
type: threadTypes.UPDATE_THREAD_PROGRESS,
2136
payload: threadServices.updateThreadProgress(id, progress)
2237
});
2338

24-
export { getThread, getCustomThread, initCustomThread, updateThreadProgress };
39+
export {
40+
getThread,
41+
getCustomThread,
42+
initCustomThread,
43+
updateThreadProgress,
44+
initCustomThreadSuccess,
45+
initCustomThreadFailure,
46+
initCustomThreadPending
47+
};

Diff for: src/redux/reducers/threadReducers.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ const threadReducers = (state = initialState, action) => {
6868
return setStateProp(
6969
'manifest',
7070
{
71-
error: action.error,
72-
errorMessage: action.payload.message
71+
error: action.payload.error,
72+
errorMessage: action.payload.error.message
7373
},
7474
{
7575
state,
@@ -97,7 +97,7 @@ const threadReducers = (state = initialState, action) => {
9797
{
9898
pending: false,
9999
fulfilled: true,
100-
data: action.payload.data
100+
data: action.payload
101101
},
102102
{
103103
state,

Diff for: src/services/threadServices.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ const initDeps = response =>
1515
})
1616
.then(resp => {
1717
if (resp.status !== 200) {
18-
return reject(new Error('An error occurred while initializing the dependencies'));
18+
const errorMsg =
19+
resp.response && resp.response.data && resp.response.data.error
20+
? resp.response.data.error
21+
: 'An error occurred while initializing the dependencies';
22+
return reject(new Error(errorMsg));
1923
}
2024
return resolve(response);
2125
})

Diff for: src/services/walkthroughServices.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ import {
1313
routeDef
1414
} from '../common/openshiftResourceDefinitions';
1515
import { addWalkthroughService, removeWalkthroughService } from '../redux/actions/walkthroughServiceActions';
16+
import {
17+
initCustomThreadPending,
18+
initCustomThreadSuccess,
19+
initCustomThreadFailure
20+
} from '../redux/actions/threadActions';
1621

1722
const DEFAULT_SERVICE_INSTANCE = {
1823
kind: 'ServiceInstance',
@@ -34,9 +39,11 @@ const prepareCustomWalkthroughNamespace = (dispatch, walkthoughName) => {
3439
if (window.OPENSHIFT_CONFIG.mockData) {
3540
return Promise.resolve([]);
3641
}
42+
dispatch(initCustomThreadPending());
3743
return initCustomThread(walkthoughName)
3844
.then(res => res.data)
3945
.then(manifest => {
46+
dispatch(initCustomThreadSuccess(manifest));
4047
currentUser().then(user => {
4148
const userNamespace = buildValidProjectNamespaceName(user.username, walkthoughName);
4249
const namespaceObj = namespaceResource(userNamespace);
@@ -67,7 +74,8 @@ const prepareCustomWalkthroughNamespace = (dispatch, walkthoughName) => {
6774
);
6875
});
6976
});
70-
});
77+
})
78+
.catch(e => dispatch(initCustomThreadFailure(e)));
7179
};
7280

7381
/**

0 commit comments

Comments
 (0)