Adding electricity emission entry fails because of backend error.
Closed this issue · 3 comments
When trying to add an emission entry for electricity emissions, the backend fails with the following error message:
{
"message": "local variable 'co2e' referenced before assignment",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"createElectricity"
]
}
This is the request I'm sending:
{
"timestamp": "2021-05-01",
"consumption": 1000,
"fuelType": "Germany energy mix",
"building": "205",
"groupShare": 1
}
I was able to track this down as a result of an invalid fuelType
.
@redfrexx @veitu The problem with synchronisation issues, especially regarding the fuelType or the transportation modes names, have come up very often recently. Can we:
- Add error boundaries to the co2 package and the api backend? I would suggest creating a custom exception s.a.
invalidFuelTypeException
orinvalidTransportationModeException
instead of just throwing a Key or Type error. - Is there a way we can use enums in the backend that handle these kind of things? I would regard the backend as the SSOT in terms of these typings and the frontend to just consume some endpoint that provides fixed typings
Add error boundaries to the co2 package and the api backend? I would suggest creating a custom exception s.a. invalidFuelTypeException or invalidTransportationModeException instead of just throwing a Key or Type error.
yes sounds good. I've started creating custom exceptions in the co2calculator package anyways. would make sense to add more specific ones to check the user input.
Is there a way we can use enums in the backend that handle these kind of things? I would regard the backend as the SSOT in terms of these typings and the frontend to just consume some endpoint that provides fixed typings
Yes, I think we've already talked about this some time ago (#111), and I also implemented an endpoint some time ago but only to test if it would work. Not sure if this query still works. Do you think queries like this would work from the frontend side?
Do you think queries like this would work from the frontend side?
Yes, I didn't know about their existence. I will try to implement them in the frontend (see #239 )