Skip to content

TDMQ REST API should return an error in case of entity category missing #49

@svituz

Description

@svituz

Description

Using the REST API, when a client tries to make a POST of a new Source with an entity_type/entity_category pair which is not present in the DB, the server returns an error page
which states that a psycopg2 error occurred. The API should, instead, handle the error and return an appropriate response specifying it.

How to reproduce

In your local machine, launch the docker development env then, using your favorite client (e.g., postman), try to perform a POST to /api/v0.0/sources call using the following json body:

[{
	"id": "AN.EDGE.ID", 
	"alias": "AN.EDGE.ALIAS", 
	"entity_type": "NONEXISTENT-TYPE", 
	"entity_category": "NONEXISTENT-CAT", 
	"default_footprint": {
		"type": "Point", 
		"coordinates": ["0","0"]		
	}, 
	"stationary": true,
	"controlledProperties": [
		"humidity", 
		"temperature", 
		"dewpoint"
	], 
	"shape": [], 
	"description": {}
}]

Notice that the important attributes are entity type and category, other values are irrelevant.

What happens

The server returns a 500 Internal Server Error with a the exception:

"psycopg2.errors.ForeignKeyViolation: insert or update on table "source" violates foreign key constraint "source_entity_category_fkey" DETAIL: Key (entity_category, entity_type)=(Station, DeviceStatus) is not present in table "entity_type".

What should happen

The server should return an appropriate error code (TBD) and a JSON response with some error details.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions