Skip to content

Commit

Permalink
return precondition failed in update profile
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacavallaro committed Dec 18, 2023
1 parent 15590d4 commit b344a60
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"@pagopa/io-functions-commons": "28.9.0",
"@pagopa/io-functions-eucovidcerts-sdk": "x",
"@pagopa/io-spid-commons": "^13.3.0",
"@pagopa/ts-commons": "^12.3.0",
"@pagopa/ts-commons": "^12.4.0",
"@pagopa/winston-ts": "^2.2.0",
"applicationinsights": "^1.8.10",
"body-parser": "^1.19.2",
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/profileController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
IResponseErrorConflict,
IResponseErrorInternal,
IResponseErrorNotFound,
IResponseErrorPreconditionFailed,
IResponseErrorTooManyRequests,
IResponseErrorValidation,
IResponseSuccessAccepted,
Expand Down Expand Up @@ -76,6 +77,7 @@ export default class ProfileController {
| IResponseErrorInternal
| IResponseErrorConflict
| IResponseErrorTooManyRequests
| IResponseErrorPreconditionFailed
| IResponseSuccessJson<InitializedProfile>
> =>
withUserFromRequest(req, async (user) =>
Expand Down
36 changes: 24 additions & 12 deletions src/services/profileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import {
IResponseErrorConflict,
IResponseErrorInternal,
IResponseErrorNotFound,
IResponseErrorPreconditionFailed,
IResponseErrorTooManyRequests,
IResponseSuccessAccepted,
IResponseSuccessJson,
ResponseErrorConflict,
ResponseErrorInternal,
ResponseErrorNotFound,
ResponseErrorPreconditionFailed,
ResponseErrorTooManyRequests,
ResponseSuccessAccepted,
ResponseSuccessJson,
Expand Down Expand Up @@ -174,6 +176,7 @@ export default class ProfileService {
| IResponseErrorNotFound
| IResponseErrorConflict
| IResponseErrorTooManyRequests
| IResponseErrorPreconditionFailed
| IResponseSuccessJson<InitializedProfile>
> => {
const client = this.apiClient.getClient();
Expand All @@ -189,19 +192,28 @@ export default class ProfileService {
fiscal_code: user.fiscal_code,
});

return withValidatedOrInternalError(validated, (response) =>
response.status === 200
? ResponseSuccessJson(toInitializedProfile(response.value, user))
: response.status === 404
? ResponseErrorNotFound("Not found", "User not found")
: response.status === 409
? ResponseErrorConflict(
return withValidatedOrInternalError(validated, (response) => {
switch (response.status) {
case 200:
return ResponseSuccessJson(
toInitializedProfile(response.value, user)
);
case 404:
return ResponseErrorNotFound("Not found", "User not found");
case 409:
return ResponseErrorConflict(
response.value || "Cannot update profile with wrong version"
)
: response.status === 429
? ResponseErrorTooManyRequests()
: unhandledResponseStatus(response.status)
);
);
case 412:
return ResponseErrorPreconditionFailed(
"The provided e-mail address is not unique"
);
case 429:
return ResponseErrorTooManyRequests();
default:
return unhandledResponseStatus(response.status);
}
});
})
);
};
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1123,10 +1123,10 @@
semver "^7.3.7"
validator "^13.7.0"

"@pagopa/ts-commons@^12.3.0":
version "12.3.0"
resolved "https://registry.yarnpkg.com/@pagopa/ts-commons/-/ts-commons-12.3.0.tgz#54e661b71ef3b80e9a8474ba90088ffafb2c06c0"
integrity sha512-7fwd2EEhac6bmmfGdWYr5EGRjF1AwzaH3DHyg/jLcoKnQcHPWbt7tsvO0zSD/mxAbHZBrZ24zut0IK3eD3qNag==
"@pagopa/ts-commons@^12.4.0":
version "12.4.0"
resolved "https://registry.yarnpkg.com/@pagopa/ts-commons/-/ts-commons-12.4.0.tgz#58b46bd485ff0be7649cf662d9ebf0be38d8a6ff"
integrity sha512-eFDjCHmwepYPAR1+Hnm0BbXploOquZ20mnu0kKAmwLGE9Grr6WAPbjmf/5bheNWPDeD5rGUTv8ENoB2KJWOGbw==
dependencies:
abort-controller "^3.0.0"
agentkeepalive "^4.1.4"
Expand Down

0 comments on commit b344a60

Please sign in to comment.