Skip to content

Commit

Permalink
Changed all error codes from InvalidRequest to BadRequestData, except…
Browse files Browse the repository at this point in the history
… for JSON Parse Error that is still an InvalidRequest
  • Loading branch information
kzangeli committed Aug 31, 2023
1 parent 0f6b273 commit b091107
Show file tree
Hide file tree
Showing 21 changed files with 199 additions and 39 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ Fixed issues:
* #1419 - Fixed a bug in the cleanup of the "URL being downloaded list" - not being cleaned up in case of an error
* #280 - Added extensive logging for downloading of contexts
* #280 - Fixed two erroneous type values in the response payload body (EntityTypeInformation => EntityTypeInfo and EntityAttributeList => AttributeList)
* #280 - Changed all error codes from InvalidRequest to BadRequestData, except for JSON Parse Error that is still an InvalidRequest
12 changes: 6 additions & 6 deletions src/lib/orionld/common/httpStatusCodeToOrionldErrorType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ OrionldResponseErrorType httpStatusCodeToOrionldErrorType(int httpStatusCode)
case 400: return OrionldBadRequestData;
case 403: return OrionldOperationNotSupported;
case 404: return OrionldResourceNotFound;
case 405: return OrionldInvalidRequest;
case 406: return OrionldInvalidRequest;
case 405: return OrionldBadRequestData;
case 406: return OrionldBadRequestData;
case 409: return OrionldAlreadyExists;
case 411: return OrionldInvalidRequest;
case 413: return OrionldInvalidRequest;
case 415: return OrionldInvalidRequest;
case 411: return OrionldBadRequestData;
case 413: return OrionldBadRequestData;
case 415: return OrionldBadRequestData;
case 422: return OrionldOperationNotSupported;
case 470: return OrionldResourceNotFound;
case 471: return OrionldBadRequestData;
case 472: return OrionldBadRequestData;
case 473: return OrionldBadRequestData;
case 480: return OrionldBadRequestData;
case 481: return OrionldBadRequestData;
case 482: return OrionldInvalidRequest;
case 482: return OrionldBadRequestData;
case 500: return OrionldInternalError;
case 501: return OrionldOperationNotSupported;
case 503: return OrionldInternalError;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/orionld/mongoc/mongocEntitiesQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ static bool geoOverlapsFilter(bson_t* mongoFilterP, OrionldGeoInfo* geoInfoP)
//
static bool geoContainsFilter(bson_t* mongoFilterP, OrionldGeoInfo* geoInfoP)
{
orionldError(OrionldInvalidRequest, "Not Implemented", "georel 'contains' is not supported by mongodb and thus also not by Orion-LD", 501);
orionldError(OrionldOperationNotSupported, "Not Implemented", "georel 'contains' is not supported by mongodb and thus also not by Orion-LD", 501);
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions src/lib/orionld/payloadCheck/pCheckGeorel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ bool pCheckGeorel(KjNode* georelP, OrionldGeoInfo* geoInfoP)
{
if (georelP == NULL)
{
orionldError(OrionldInvalidRequest, "Invalid Geo-Spatial Filter", "georel missing", 400);
orionldError(OrionldBadRequestData, "Invalid Geo-Spatial Filter", "georel missing", 400);
return false;
}
else if (georelP->type != KjString)
{
orionldError(OrionldInvalidRequest, "Invalid Geo-Spatial Filter", "georel must be a string", 400);
orionldError(OrionldBadRequestData, "Invalid Geo-Spatial Filter", "georel must be a string", 400);
return false;
}
else if (georelP->value.s[0] == 0)
{
orionldError(OrionldInvalidRequest, "Invalid Geo-Spatial Filter", "georel value is empty", 400);
orionldError(OrionldBadRequestData, "Invalid Geo-Spatial Filter", "georel value is empty", 400);
return false;
}

Expand Down
14 changes: 7 additions & 7 deletions src/lib/orionld/payloadCheck/pCheckGeorelString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ bool pCheckGeorelString(const char* georel, OrionldGeoInfo* geoInfoP)
{
if (geoInfoP->geometry != GeoPoint)
{
orionldError(OrionldInvalidRequest, "Invalid Geo-Spatial filter", "Geometry must be 'Point' for georel 'near'", 400);
orionldError(OrionldBadRequestData, "Invalid Geo-Spatial filter", "Geometry must be 'Point' for georel 'near'", 400);
return false;
}
}
else if (strcmp(georel, "within") == 0)
{
if ((geoInfoP->geometry != GeoPolygon) && (geoInfoP->geometry != GeoMultiPolygon))
{
orionldError(OrionldInvalidRequest, "Invalid Geo-Spatial filter", "Geometry must be either 'Polygon' or 'MultiPolygon' for georel 'within'", 400);
orionldError(OrionldBadRequestData, "Invalid Geo-Spatial filter", "Geometry must be either 'Polygon' or 'MultiPolygon' for georel 'within'", 400);
return false;
}
geoInfoP->georel = GeorelWithin;
Expand Down Expand Up @@ -105,7 +105,7 @@ bool pCheckGeorelString(const char* georel, OrionldGeoInfo* geoInfoP)
}
else
{
orionldError(OrionldInvalidRequest, "Invalid Geo-Spatial filter - invalid 'georel'", georel, 400);
orionldError(OrionldBadRequestData, "Invalid Geo-Spatial filter - invalid 'georel'", georel, 400);
return false;
}

Expand All @@ -126,7 +126,7 @@ bool pCheckGeorelString(const char* georel, OrionldGeoInfo* geoInfoP)

if (strcmp(grel, "near") != 0)
{
orionldError(OrionldInvalidRequest, "Invalid Geo-Spatial filter", "invalid geo-relation for Point", 400);
orionldError(OrionldBadRequestData, "Invalid Geo-Spatial filter", "invalid geo-relation for Point", 400);
return false;
}
geoInfoP->georel = GeorelNear;
Expand All @@ -138,7 +138,7 @@ bool pCheckGeorelString(const char* georel, OrionldGeoInfo* geoInfoP)

if (distance == NULL)
{
orionldError(OrionldInvalidRequest, "Invalid Geo-Spatial filter", "no distance for georel 'near' for Point", 400);
orionldError(OrionldBadRequestData, "Invalid Geo-Spatial filter", "no distance for georel 'near' for Point", 400);
return false;
}
*distance = 0;
Expand All @@ -151,7 +151,7 @@ bool pCheckGeorelString(const char* georel, OrionldGeoInfo* geoInfoP)
max = false;
else
{
orionldError(OrionldInvalidRequest, "Invalid Geo-Spatial filter", "no distance for georel 'near' for Point", 400);
orionldError(OrionldBadRequestData, "Invalid Geo-Spatial filter", "no distance for georel 'near' for Point", 400);
return false;
}

Expand All @@ -163,7 +163,7 @@ bool pCheckGeorelString(const char* georel, OrionldGeoInfo* geoInfoP)
{
if ((*distance < '0') || (*distance > '9'))
{
orionldError(OrionldInvalidRequest, "Invalid Geo-Spatial filter", "invalid number for distance for georel 'near' for Point", 400);
orionldError(OrionldBadRequestData, "Invalid Geo-Spatial filter", "invalid number for distance for georel 'near' for Point", 400);
return false;
}
++distance;
Expand Down
10 changes: 5 additions & 5 deletions src/lib/orionld/rest/orionldMhdConnectionTreat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,14 @@ static bool payloadEmptyCheck(void)
// No payload?
if (orionldState.in.payload == NULL)
{
orionldError(OrionldInvalidRequest, "payload missing", NULL, 400);
orionldError(OrionldBadRequestData, "payload missing", NULL, 400);
return false;
}

// Empty payload?
if (orionldState.in.payload[0] == 0)
{
orionldError(OrionldInvalidRequest, "payload missing", NULL, 400);
orionldError(OrionldBadRequestData, "payload missing", NULL, 400);
return false;
}

Expand Down Expand Up @@ -262,7 +262,7 @@ static bool payloadParseAndExtractSpecialFields(bool* contextToBeCashedP)
//
if ((orionldState.requestTree->type != KjArray) && (orionldState.requestTree->type != KjObject))
{
orionldError(OrionldInvalidRequest, "Invalid Payload", "The payload data must be either a JSON Array or a JSON Object", 400);
orionldError(OrionldBadRequestData, "Invalid Payload", "The payload data must be either a JSON Array or a JSON Object", 400);
return false;
}

Expand All @@ -271,7 +271,7 @@ static bool payloadParseAndExtractSpecialFields(bool* contextToBeCashedP)
//
if ((orionldState.requestTree->type == KjObject) && (orionldState.requestTree->value.firstChildP == NULL))
{
orionldError(OrionldInvalidRequest, "Invalid Payload Body", "Empty Object", 400);
orionldError(OrionldBadRequestData, "Invalid Payload Body", "Empty Object", 400);
return false;
}

Expand All @@ -280,7 +280,7 @@ static bool payloadParseAndExtractSpecialFields(bool* contextToBeCashedP)
//
if ((orionldState.requestTree->type == KjArray) && (orionldState.requestTree->value.firstChildP == NULL))
{
orionldError(OrionldInvalidRequest, "Invalid Payload Body", "Empty Array", 400);
orionldError(OrionldBadRequestData, "Invalid Payload Body", "Empty Array", 400);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ Date: REGEX(.*)
{
"detail": "Empty Array",
"title": "Invalid Payload Body",
"type": "https://uri.etsi.org/ngsi-ld/errors/InvalidRequest"
"type": "https://uri.etsi.org/ngsi-ld/errors/BadRequestData"
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ Date: REGEX(.*)
{
"detail": "Empty Array",
"title": "Invalid Payload Body",
"type": "https://uri.etsi.org/ngsi-ld/errors/InvalidRequest"
"type": "https://uri.etsi.org/ngsi-ld/errors/BadRequestData"
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ Content-Type: application/json
Date: REGEX(.*)

{
"type": "https://uri.etsi.org/ngsi-ld/errors/InvalidRequest",
"type": "https://uri.etsi.org/ngsi-ld/errors/BadRequestData",
"title": "Invalid Payload Body",
"detail": "Empty Array"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ Content-Type: application/json
Date: REGEX(.*)

{
"type": "https://uri.etsi.org/ngsi-ld/errors/InvalidRequest",
"type": "https://uri.etsi.org/ngsi-ld/errors/BadRequestData",
"title": "Invalid Payload Body",
"detail": "Empty Array"
}
Expand Down
8 changes: 4 additions & 4 deletions test/functionalTest/cases/0000_ngsild/ngsild_issue_0029.test
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Content-Type: application/json
Date: REGEX(.*)

{
"type": "https://uri.etsi.org/ngsi-ld/errors/InvalidRequest",
"type": "https://uri.etsi.org/ngsi-ld/errors/BadRequestData",
"title": "Invalid Payload Body",
"detail": "Empty Object"
}
Expand All @@ -87,7 +87,7 @@ Content-Type: application/json
Date: REGEX(.*)

{
"type": "https://uri.etsi.org/ngsi-ld/errors/InvalidRequest",
"type": "https://uri.etsi.org/ngsi-ld/errors/BadRequestData",
"title": "payload missing",
"detail": "no detail"
}
Expand All @@ -102,7 +102,7 @@ Content-Type: application/json
Date: REGEX(.*)

{
"type": "https://uri.etsi.org/ngsi-ld/errors/InvalidRequest",
"type": "https://uri.etsi.org/ngsi-ld/errors/BadRequestData",
"title": "payload missing",
"detail": "no detail"
}
Expand All @@ -117,7 +117,7 @@ Content-Type: application/json
Date: REGEX(.*)

{
"type": "https://uri.etsi.org/ngsi-ld/errors/InvalidRequest",
"type": "https://uri.etsi.org/ngsi-ld/errors/BadRequestData",
"title": "Invalid Payload Body",
"detail": "Empty Array"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Date: REGEX(.*)
{
"detail": "The payload data must be either a JSON Array or a JSON Object",
"title": "Invalid Payload",
"type": "https://uri.etsi.org/ngsi-ld/errors/InvalidRequest"
"type": "https://uri.etsi.org/ngsi-ld/errors/BadRequestData"
}


Expand Down
Loading

0 comments on commit b091107

Please sign in to comment.