Skip to content

Commit

Permalink
Merge pull request #9 from gferraro/initialIssues
Browse files Browse the repository at this point in the history
Initial issues fixes #8 #6 #4 #3
  • Loading branch information
gferraro authored Dec 13, 2018
2 parents 46b9d1c + e040a47 commit 58d21fc
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 42 deletions.
39 changes: 2 additions & 37 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,35 +371,8 @@ func handleHTTPResponse(resp *http.Response) error {
return nil
}

// Error is returned by API calling methods. As well as an error
// message, it includes whether the error is permanent or not.
type Error struct {
message string
permanent bool
}

// Error implemented the error interface.
func (e *Error) Error() string {
return e.message
}

// Permanent returns true if the error is permanent. Operations
// resulting in non-permanent/temporary errors may be retried.
func (e *Error) Permanent() bool {
return e.permanent
}

// IsPermanentError examines the supplied error and returns true if it
// is permanent.
func IsPermanentError(err error) bool {
if err == nil {
return false
}
if apiErr, ok := err.(*Error); ok {
return apiErr.Permanent()
}
// non-Errors are considered permanent.
return true
func formatTimestamp(t time.Time) string {
return t.UTC().Format(time.RFC3339)
}

func isHTTPSuccess(code int) bool {
Expand All @@ -410,14 +383,6 @@ func isHTTPClientError(code int) bool {
return code >= 400 && code < 500
}

func temporaryError(err error) *Error {
return &Error{message: err.Error(), permanent: false}
}

func formatTimestamp(t time.Time) string {
return t.UTC().Format(time.RFC3339)
}

// GetSchedule will get the audio schedule
func (api *CacophonyAPI) GetSchedule() ([]byte, error) {
req, err := http.NewRequest("GET", api.serverURL+basePath+"schedules", nil)
Expand Down
6 changes: 3 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ package api
import (
"errors"
"fmt"
yaml "gopkg.in/yaml.v2"
"io/ioutil"
"os"
"path/filepath"
"strings"

yaml "gopkg.in/yaml.v2"
)

type Config struct {
Expand Down Expand Up @@ -92,8 +93,6 @@ func WritePassword(filename, password string) error {
}

func Open(configFile string) (*CacophonyAPI, error) {
// TODO(mjs) - much of this is copied straight from
// thermal-uploader and should be extracted.
conf, err := ParseConfigFile(configFile)
if err != nil {
return nil, fmt.Errorf("configuration error: %v", err)
Expand All @@ -113,6 +112,7 @@ func Open(configFile string) (*CacophonyAPI, error) {
// event-reporter register at about the same time. Extract this to
// a library which does locking.
if api.JustRegistered() {

err := WritePassword(privConfigFilename, api.Password())
if err != nil {
return nil, err
Expand Down
51 changes: 51 additions & 0 deletions error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// go-api - Client for the Cacophony API server.
// Copyright (C) 2018, The Cacophony Project
//
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.

package api

// Error is returned by API calling methods. As well as an error
// message, it includes whether the error is permanent or not.
type Error struct {
message string
permanent bool
}

// Error implements the error interface.
func (e *Error) Error() string {
return e.message
}

// Permanent returns true if the error is permanent. Operations
// resulting in non-permanent/temporary errors may be retried.
func (e *Error) Permanent() bool {
return e.permanent
}

// IsPermanentError examines the supplied error and returns true if it
// is permanent.
func IsPermanentError(err error) bool {
if err == nil {
return false
}
if apiErr, ok := err.(*Error); ok {
return apiErr.Permanent()
}
// non-Errors are considered permanent.
return true
}

func temporaryError(err error) *Error {
return &Error{message: err.Error(), permanent: false}
}
2 changes: 0 additions & 2 deletions randstring.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Copyright (C) 2017, The Cacophony Project
//
// go-api - Client for the Cacophony API server.
// Copyright (C) 2018, The Cacophony Project
//
Expand Down

0 comments on commit 58d21fc

Please sign in to comment.