Changeset View
Changeset View
Standalone View
Standalone View
assets/src/bundles/add_forge/create-request.js
Show All 17 Lines | $('#requestCreateForm').submit(async function(event) { | ||||||||||||||||||||||
{'Content-Type': 'application/x-www-form-urlencoded'}, | {'Content-Type': 'application/x-www-form-urlencoded'}, | ||||||||||||||||||||||
$(this).serialize()); | $(this).serialize()); | ||||||||||||||||||||||
handleFetchError(response); | handleFetchError(response); | ||||||||||||||||||||||
$('#userMessageDetail').empty(); | $('#userMessageDetail').empty(); | ||||||||||||||||||||||
$('#userMessage').text('Your request has been submitted'); | $('#userMessage').text('Your request has been submitted'); | ||||||||||||||||||||||
$('#userMessage').removeClass('badge-danger'); | $('#userMessage').removeClass('badge-danger'); | ||||||||||||||||||||||
$('#userMessage').addClass('badge-success'); | $('#userMessage').addClass('badge-success'); | ||||||||||||||||||||||
requestBrowseTable.draw(); // redraw the table to update the list | requestBrowseTable.draw(); // redraw the table to update the list | ||||||||||||||||||||||
} catch (response) { | } catch (errorResponse) { | ||||||||||||||||||||||
const responseText = await response.json(); | |||||||||||||||||||||||
$('#userMessageDetail').empty(); | $('#userMessageDetail').empty(); | ||||||||||||||||||||||
$('#userMessage').text('Sorry; an error occurred'); | |||||||||||||||||||||||
$('#userMessageDetail').text(responseText.substring(0, 500)); | let errorMessage; | ||||||||||||||||||||||
let errorMessageDetail = ''; | |||||||||||||||||||||||
const errorData = await errorResponse.json(); | |||||||||||||||||||||||
// if (errorResponse.content_type === 'text/plain') { // does not work? | |||||||||||||||||||||||
if (errorResponse.status === 409) { | |||||||||||||||||||||||
errorMessage = errorData; | |||||||||||||||||||||||
} else { // assuming json response | |||||||||||||||||||||||
// const exception = errorData['exception']; | |||||||||||||||||||||||
errorMessage = 'An unknown error occurred during the request creation'; | |||||||||||||||||||||||
try { | |||||||||||||||||||||||
const reason = JSON.parse(errorData['reason']); | |||||||||||||||||||||||
Object.entries(reason).forEach((keys, _) => { | |||||||||||||||||||||||
const key = keys[0]; | |||||||||||||||||||||||
const message = keys[1][0]; // take only the first issue | |||||||||||||||||||||||
errorMessageDetail += `\n${key}: ${message}`; | |||||||||||||||||||||||
}); | |||||||||||||||||||||||
} catch (_) { | |||||||||||||||||||||||
errorMessageDetail = errorData['reason']; // can't parse it, leave it raw | |||||||||||||||||||||||
ardumont: As another simplification step (for another diff), we'll probably want to massage a bit more… | |||||||||||||||||||||||
Done Inline Actionsmissing coverage: i've got a stashed failed attempd for that in a stash... [1] [1] P1314 ardumont: missing coverage: i've got a stashed failed attempd for that in a stash... [1]
i don't… | |||||||||||||||||||||||
Not Done Inline ActionsYou need to indicate it is a POST request in the intercept: cy.intercept('POST', `${this.Urls.api_1_add_forge_request_create()}**`, {fixture: 'add-forge-now-create-request-fail'}).as('errorRequest'); anlambert: You need to indicate it is a POST request in the intercept:
```lang=javascript
cy.intercept… | |||||||||||||||||||||||
Done Inline Actionsdo'h right, thx. ardumont: do'h right, thx. | |||||||||||||||||||||||
} | |||||||||||||||||||||||
} | |||||||||||||||||||||||
$('#userMessage').text( | |||||||||||||||||||||||
Done Inline Actions
No need to have two error messages. vlorentz: No need to have two error messages. | |||||||||||||||||||||||
Done Inline ActionsAdapted accordingly, i've updated the screenshots (in the diff description) as well. ardumont: Adapted accordingly, i've updated the screenshots (in the diff description) as well. | |||||||||||||||||||||||
errorMessageDetail ? `Error: ${errorMessageDetail}` : errorMessage | |||||||||||||||||||||||
); | |||||||||||||||||||||||
$('#userMessage').removeClass('badge-success'); | $('#userMessage').removeClass('badge-success'); | ||||||||||||||||||||||
$('#userMessage').addClass('badge-danger'); | $('#userMessage').addClass('badge-danger'); | ||||||||||||||||||||||
} | } | ||||||||||||||||||||||
}); | }); | ||||||||||||||||||||||
$(window).on('hashchange', () => { | $(window).on('hashchange', () => { | ||||||||||||||||||||||
if (window.location.hash === '#browse-requests') { | if (window.location.hash === '#browse-requests') { | ||||||||||||||||||||||
$('.nav-tabs a[href="#swh-add-forge-requests-list"]').tab('show'); | $('.nav-tabs a[href="#swh-add-forge-requests-list"]').tab('show'); | ||||||||||||||||||||||
▲ Show 20 Lines • Show All 54 Lines • Show Last 20 Lines |
As another simplification step (for another diff), we'll probably want to massage a bit more the actual api error message case [1] to avoid this convolution ^ [1].
[1] https://forge.softwareheritage.org/source/swh-web/browse/sprint-add-forge-now/swh/web/api/views/add_forge_now.py$131