check status on upload, query escape cities for formatting maps uri format

master v0.0.10
Bel LaPointe 2022-01-13 00:17:41 -05:00
parent 5170e96f7e
commit 1cc082083c
2 changed files with 8 additions and 2 deletions

View File

@ -9,6 +9,7 @@ import (
"local/truckstop/config"
"local/truckstop/message"
"log"
"net/url"
"regexp"
"sort"
"strings"
@ -311,7 +312,7 @@ func sendJob(job broker.Job) error {
}
maps := config.Get().Maps
if maps.Pickup {
pickup := fmt.Sprintf("%s,%s", job.Pickup.City, job.Pickup.State)
pickup := fmt.Sprintf("%s,%s", url.QueryEscape(job.Pickup.City), job.Pickup.State)
uri := fmt.Sprintf(maps.URIFormat, pickup, pickup)
log.Printf("sending pickup image: %s", uri)
if err := sender.SendImage(uri); err != nil {
@ -319,7 +320,7 @@ func sendJob(job broker.Job) error {
}
}
if maps.Dropoff {
dropoff := fmt.Sprintf("%s,%s", job.Dropoff.City, job.Dropoff.State)
dropoff := fmt.Sprintf("%s,%s", url.QueryEscape(job.Dropoff.City), job.Dropoff.State)
uri := fmt.Sprintf(maps.URIFormat, dropoff, dropoff)
log.Printf("sending dropoff image: %s", uri)
if err := sender.SendImage(uri); err != nil {

View File

@ -119,6 +119,11 @@ func (m Matrix) SendImage(uri string) error {
if err != nil {
return err
}
if response.StatusCode != http.StatusOK {
b, _ := ioutil.ReadAll(response.Body)
response.Body.Close()
return fmt.Errorf("failed to get %s: (%d) %s", uri, response.StatusCode, b)
}
b, err := ioutil.ReadAll(response.Body)
response.Body.Close()
if err != nil {