Merge pull request #36 from PeteBa/fix-options-hardening
Harden against malformed api request
This commit is contained in:
@@ -125,7 +125,7 @@ You should see "OpenSprinkler Weather Service" in response.
|
|||||||
You can use the following request to see the watering level that the Weather Service calculates. Note: to be consistent, change the values of h, t and r to the % weightings and bh (as a %), bt (in F), bp (in inches) to the offsets from the Zimmerman config page in App.
|
You can use the following request to see the watering level that the Weather Service calculates. Note: to be consistent, change the values of h, t and r to the % weightings and bh (as a %), bt (in F), bp (in inches) to the offsets from the Zimmerman config page in App.
|
||||||
|
|
||||||
```
|
```
|
||||||
http://<Weather Service IP>:3000/weather1.py?loc=50,1&wto="\"h\":100,\"t\":100,\"r\":100,\"bh\":70,\"bt\":59,\"br\":0"
|
http://<Weather Service IP>:3000/weather1.py?loc=50,1&wto="h":100,"t":100,"r":100,"bh":70,"bt":59,"br":0
|
||||||
```
|
```
|
||||||
|
|
||||||
This will return a response similar to below with ```scale``` value equating to the watering level and ```rawData``` reflecting the temp (F), humidity (%) and daily rainfall (inches) used in the zimmerman calc.
|
This will return a response similar to below with ```scale``` value equating to the watering level and ```rawData``` reflecting the temp (F), humidity (%) and daily rainfall (inches) used in the zimmerman calc.
|
||||||
|
|||||||
@@ -242,8 +242,9 @@ export const getWateringData = async function( req: express.Request, res: expres
|
|||||||
adjustmentOptions = JSON.parse( "{" + adjustmentOptionsString + "}" );
|
adjustmentOptions = JSON.parse( "{" + adjustmentOptionsString + "}" );
|
||||||
} catch ( err ) {
|
} catch ( err ) {
|
||||||
|
|
||||||
// If the JSON is not valid, do not incorporate weather adjustment options
|
// If the JSON is not valid then abort the claculation
|
||||||
adjustmentOptions = undefined;
|
res.send(`Error: Unable to parse options (${err})`);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to resolve provided location to GPS coordinates.
|
// Attempt to resolve provided location to GPS coordinates.
|
||||||
|
|||||||
Reference in New Issue
Block a user