jembi / openhim-mediator-mapping

An OpenHIM mediator for mapping incoming content to a different format
https://jembi.github.io/openhim-mediator-mapping/
MIT License
3 stars 6 forks source link

State management: Failures cases #73

Closed BMartinos closed 3 years ago

BMartinos commented 4 years ago

Currently, the request state is being capured for each request that comes through on an endpoint. This state is currently saved regardless of the request status.

This means that if a request fails for any reason, eg a 400 Bad Request at an external lookup, or a 500 internal server error, the state for this failure is seen as the last captured state which will be used on a subsequent request.

This presents an issue when using the internal timestamp states captured because if you make use of this timestamp as a since parameter, it will not be accurate in terms of when the previous request was actually completed.

Request 1 (2020-04-25T10:00:000Z) - No State - extract parameter => _since= Request 2 (2020-04-26T10:00:000Z) - No State - extract parameter => _since=2020-04-25T10:00:000Z Request 3 (2020-04-27T10:00:000Z) FAILED - No State - extract parameter => _since=2020-04-26T10:00:000Z Request 4 (2020-04-28T10:00:000Z) - No State - extract parameter => _since=2020-04-27T10:00:000Z

Request 4 should have a _since parameter of 2020-04-26T10:00:000Z because the request on the 27th was not successful

Fix

Update the states model to also capture the request statusCode. This statusCode will then be used in the states lookup request to find the last successful state that was triggered.

MattyJ007 commented 3 years ago

Fixed as of v2 😄