Return a json error on failed database constraints for door sensor #106

Open
opened 2026-01-12 13:46:46 +01:00 by oysteikt · 0 comments
Owner

This happens when I try to submit the same timestamp multiple times.

$ curl http://localhost:1080/door -X POST --json '{ "isDoorOpen": true, "time": 1767883500 }'
<br />
<b>Notice</b>:  Only variables should be passed by reference in <b>/home/h7x4/pvv/nettsiden/src/pvv/side/door.php</b> on line <b>80</b><br />
<br />
<b>Fatal error</b>:  Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed: door.time in /home/h7x4/pvv/nettsiden/src/pvv/side/door.php:82
Stack trace:
#0 /home/h7x4/pvv/nettsiden/src/pvv/side/door.php(82): PDOStatement-&gt;execute()
#1 /home/h7x4/pvv/nettsiden/www/door/index.php(81): pvv\side\Door-&gt;createEvent(Object(DateTimeImmutable), 1)
#2 /home/h7x4/pvv/nettsiden/www/door/index.php(15): handleSetState()
#3 {main}
  thrown in <b>/home/h7x4/pvv/nettsiden/src/pvv/side/door.php</b> on line <b>82</b><br />
This happens when I try to submit the same timestamp multiple times. ``` $ curl http://localhost:1080/door -X POST --json '{ "isDoorOpen": true, "time": 1767883500 }' <br /> <b>Notice</b>: Only variables should be passed by reference in <b>/home/h7x4/pvv/nettsiden/src/pvv/side/door.php</b> on line <b>80</b><br /> <br /> <b>Fatal error</b>: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed: door.time in /home/h7x4/pvv/nettsiden/src/pvv/side/door.php:82 Stack trace: #0 /home/h7x4/pvv/nettsiden/src/pvv/side/door.php(82): PDOStatement-&gt;execute() #1 /home/h7x4/pvv/nettsiden/www/door/index.php(81): pvv\side\Door-&gt;createEvent(Object(DateTimeImmutable), 1) #2 /home/h7x4/pvv/nettsiden/www/door/index.php(15): handleSetState() #3 {main} thrown in <b>/home/h7x4/pvv/nettsiden/src/pvv/side/door.php</b> on line <b>82</b><br /> ```
oysteikt added the bugcrash report labels 2026-01-12 13:46:46 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Projects/nettsiden#106