Skip to content

Commit

Permalink
FIX improve problematic attribute reporting on updates
Browse files Browse the repository at this point in the history
  • Loading branch information
fgalan committed Nov 17, 2023
1 parent f6a1c07 commit a772397
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
36 changes: 27 additions & 9 deletions src/lib/mongoBackend/MongoCommonUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2448,7 +2448,7 @@ static bool updateContextAttributeItem
" - offending attribute: " + targetAttr->getName();

cerP->statusCode.fill(SccInvalidParameter, details);
oe->fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ATTRIBUTE, ERROR_NOT_FOUND);
//oe->fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ATTRIBUTE, ERROR_NOT_FOUND);

/* Although 'ca' has been already pushed into cerP, the pointer is still valid, of course */
ca->found = false;
Expand Down Expand Up @@ -2613,7 +2613,7 @@ static bool deleteContextAttributeItem
" - attribute not found";

cerP->statusCode.fill(SccInvalidParameter, details);
oe->fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ATTRIBUTE, ERROR_NOT_FOUND);
//oe->fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ATTRIBUTE, ERROR_NOT_FOUND);

alarmMgr.badInput(clientIp, "attribute to be deleted is not found", targetAttr->getName());
ca->found = false;
Expand Down Expand Up @@ -3645,7 +3645,7 @@ static unsigned int updateEntity
*attributeAlreadyExistsList += " ]";
}

if ((apiVersion == V2) && (action == ActionTypeUpdate))
if ((apiVersion == V2) && ((action == ActionTypeUpdate) || (action == ActionTypeDelete)))
{
for (unsigned int ix = 0; ix < eP->attributeVector.size(); ++ix)
{
Expand Down Expand Up @@ -4451,16 +4451,34 @@ unsigned int processContextElement

if (attributeAlreadyExistsError == true)
{
std::string details = "one or more of the attributes in the request already exist: " + attributeAlreadyExistsList;
buildGeneralErrorResponse(eP, NULL, responseP, SccBadRequest, details);
responseP->oe.fill(SccInvalidModification, details, ERROR_UNPROCESSABLE);
if (responseP->oe.code == SccInvalidModification)
{
// Another previous entity had problems. Use appendDetails()
responseP->oe.appendDetails(", " + eP->id + " - " + attributeAlreadyExistsList);
}
else
{
// First entity with this problem. Use fill()
std::string details = "one or more of the attributes in the request already exist: " + eP->id + " - " + attributeAlreadyExistsList;
buildGeneralErrorResponse(eP, NULL, responseP, SccBadRequest, details);
responseP->oe.fill(SccInvalidModification, details, ERROR_UNPROCESSABLE);
}
}

if (attributeNotExistingError == true)
{
std::string details = "one or more of the attributes in the request do not exist: " + attributeNotExistingList;
buildGeneralErrorResponse(eP, NULL, responseP, SccBadRequest, details);
responseP->oe.fill(SccInvalidModification, details, ERROR_UNPROCESSABLE);
if (responseP->oe.code == SccInvalidModification)
{
// Another previous entity had problems. Use appendDetails()
responseP->oe.appendDetails(", " + eP->id + " - " + attributeNotExistingList);
}
else
{
// First entity with this problem. Use fill()
std::string details = "one or more of the attributes in the request do not exist: " + eP->id + " - " + attributeNotExistingList;
buildGeneralErrorResponse(eP, NULL, responseP, SccBadRequest, details);
responseP->oe.fill(SccInvalidModification, details, ERROR_UNPROCESSABLE);
}
}

// Response in responseP
Expand Down
11 changes: 11 additions & 0 deletions src/lib/rest/OrionError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ void OrionError::fill(const StatusCode& sc)



/* ****************************************************************************
*
* OrionError::appendDetails -
*/
void OrionError::appendDetails(const std::string& _details)
{
details += _details;
}



/* ****************************************************************************
*
* OrionError::smartRender -
Expand Down
2 changes: 2 additions & 0 deletions src/lib/rest/OrionError.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ typedef struct OrionError
std::string toJsonV1(void);
void fill(HttpStatusCode _code, const std::string& _details, const std::string& _reasonPhrase = "");
void fill(const StatusCode& sc);
void appendDetails(const std::string& _details);


private:
void shrinkReasonPhrase(void);
Expand Down

0 comments on commit a772397

Please sign in to comment.