Skip to content

Commit

Permalink
Merge pull request #36 from PeteBa/fix-options-hardening
Browse files Browse the repository at this point in the history
Harden against malformed api request
  • Loading branch information
salbahra authored May 19, 2019
2 parents e6d7c3c + 5d8ab45 commit e28c309
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

```
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.
Expand Down
5 changes: 3 additions & 2 deletions routes/weather.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,9 @@ export const getWateringData = async function( req: express.Request, res: expres
adjustmentOptions = JSON.parse( "{" + adjustmentOptionsString + "}" );
} catch ( err ) {

// If the JSON is not valid, do not incorporate weather adjustment options
adjustmentOptions = undefined;
// If the JSON is not valid then abort the claculation
res.send(`Error: Unable to parse options (${err})`);
return;
}

// Attempt to resolve provided location to GPS coordinates.
Expand Down

0 comments on commit e28c309

Please sign in to comment.