mirror of
https://github.com/asciinema/asciinema.git
synced 2025-12-16 11:48:13 +01:00
Handle non-200 status from remote API
This commit is contained in:
16
api/api.go
16
api/api.go
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@@ -46,18 +47,27 @@ func (a *AsciinemaApi) CreateAsciicast(frames []Frame, duration time.Duration, c
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", errors.New(fmt.Sprintf("Connection failed (%v)", err.Error()))
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
if response.StatusCode != 200 && response.StatusCode != 201 {
|
||||
if response.StatusCode == 404 {
|
||||
return "", errors.New("Your client version is no longer supported. Please upgrade to the latest version.")
|
||||
}
|
||||
if response.StatusCode == 503 {
|
||||
return "", errors.New("The server is down for maintenance. Try again in a minute.")
|
||||
}
|
||||
|
||||
return "", errors.New("HTTP status: " + response.Status)
|
||||
}
|
||||
|
||||
body := &bytes.Buffer{}
|
||||
_, err = body.ReadFrom(response.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// TODO: handle non-200 statuses
|
||||
|
||||
return body.String(), nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user