Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(refs T34290): **breaking** Always display Messages on api responses #686

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Since v0.0.10, this Changelog is formatted according to the [Common Changelog][c

## UNRELEASED

### Changed

- ([#686](https://github.com/demos-europe/demosplan-ui/pull/686)) **breaking** add checkResponse to doRequest,
so it gets called every time a api request is fired.
It now must not be added in the leading app after using dpApi or dpRpc to avoid doubled messages

## v0.3.26 - 2024-07-30

### Fixed
Expand Down
16 changes: 12 additions & 4 deletions src/lib/DpApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,16 @@ const doRequest = (async ({ method = 'GET', url, data = {}, headers, params }) =
? await response.text()
: null

return {
const returnData = await checkResponse({
data: content,
status: response.status,
ok: response.ok,
status: response.status
}, options.messages || null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this "options" come from? Seems like it got removed in the signature of doRequest in a recent refactoring, and this was not updated accordingly.


return {
data: returnData,
ok: response.ok,
status: response.status,
statusText: response.statusText,
url: response.url
}
Expand Down Expand Up @@ -179,7 +185,9 @@ const checkResponse = function (response, messages) {
*/
} else if (dplan !== undefined && dplan.debug && hasOwnProp(response, 'errors') && hasOwnProp(response, 'meta') && hasOwnProp(response.meta, 'messages')) {
handleResponseMessages(response.meta)
} else if (messages && hasOwnProp(messages, response.status)) {
}

if (messages && hasOwnProp(messages, response.status)) {
/*
* The generic api (/api/2.0/{resourceType}) does not specify success messages.
* Instead, custom messages passed by the calling component are displayed here.
Expand All @@ -188,7 +196,7 @@ const checkResponse = function (response, messages) {
}

if (response.status >= 400) {
// @improve handle 404, 500 specially?
// handle error cases
reject(response.data)
} else if (response.status >= 200 && response.status < 400) {
// Got data!
Expand Down