Skip to content
This repository has been archived by the owner on Feb 28, 2019. It is now read-only.

Commit

Permalink
Addressing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitriy Gromov committed Oct 3, 2017
1 parent 4d6beec commit b7919bd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 30 deletions.
4 changes: 2 additions & 2 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import (
"net/http"
)

type key int
type keyType int

const (
// UserIDField is a key
UserIDField key = iota
UserIDField keyType = iota
)

// HTTPAuthService defines how to handle requests for various http authentication methods.
Expand Down
43 changes: 20 additions & 23 deletions r2/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,51 +20,48 @@

package r2

// ConflictError represents either a version mismatch writing data or a data conflict issue.
type ConflictError struct{ msg string }

// NewConflictError creates a new Conflict Error
func NewConflictError(msg string) ConflictError { return ConflictError{msg: msg} }
import "errors"

func (e ConflictError) Error() string { return e.msg }
// NewInternalError returns a new error that isn't covered by the other error types.
func NewInternalError(msg string) error { return errors.New(msg) }

// InternalError represents an unexpected server error.
type InternalError struct{ msg string }
// ConflictError represents either a version mismatch writing data or a data conflict issue.
type conflictError string

// NewInternalError creates a new Internal Error
func NewInternalError(msg string) InternalError { return InternalError{msg: msg} }
// NewConflictError creates a new Conflict Error
func NewConflictError(msg string) error { return errors.New(msg) }

func (e InternalError) Error() string { return e.msg }
func (e conflictError) Error() string { return string(e) }

// VersionError represents a mismatch in the Namespaces or Ruleset version specified in the request
// and the latest one.
type VersionError struct{ msg string }
type versionError string

// NewVersionError creates a new Version Error
func NewVersionError(msg string) VersionError { return VersionError{msg: msg} }
func NewVersionError(msg string) error { return errors.New(msg) }

func (e VersionError) Error() string { return e.msg }
func (e versionError) Error() string { return string(e) }

// BadInputError represents an error due to malformed or invalid metrics.
type BadInputError struct{ msg string }
type badInputError string

// NewBadInputError creates a new Bad Input Error.
func NewBadInputError(msg string) BadInputError { return BadInputError{msg: msg} }
func NewBadInputError(msg string) error { return errors.New(msg) }

func (e BadInputError) Error() string { return e.msg }
func (e badInputError) Error() string { return string(e) }

// NotFoundError represents an error due to malformed or invalid metrics.
type NotFoundError struct{ msg string }
type notFoundError string

// NewNotFoundError creates a new not found Error.
func NewNotFoundError(msg string) NotFoundError { return NotFoundError{msg: msg} }
func NewNotFoundError(msg string) error { return errors.New(msg) }

func (e NotFoundError) Error() string { return e.msg }
func (e notFoundError) Error() string { return string(e) }

// AuthError represents an error due to missing or invalid auth information.
type AuthError struct{ msg string }
type authError string

// NewAuthError creates a new not found Error.
func NewAuthError(msg string) AuthError { return AuthError{msg: msg} }
func NewAuthError(msg string) error { return errors.New(msg) }

func (e AuthError) Error() string { return e.msg }
func (e authError) Error() string { return string(e) }
10 changes: 5 additions & 5 deletions r2/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@ func (h r2Handler) handleError(w http.ResponseWriter, opError error) {

var err error
switch opError.(type) {
case ConflictError:
case conflictError:
err = writeAPIResponse(w, http.StatusConflict, opError.Error())
case BadInputError:
case badInputError:
err = writeAPIResponse(w, http.StatusBadRequest, opError.Error())
case VersionError:
case versionError:
err = writeAPIResponse(w, http.StatusConflict, opError.Error())
case NotFoundError:
case notFoundError:
err = writeAPIResponse(w, http.StatusNotFound, opError.Error())
case AuthError:
case authError:
err = writeAPIResponse(w, http.StatusUnauthorized, opError.Error())
default:
err = writeAPIResponse(w, http.StatusInternalServerError, opError.Error())
Expand Down

0 comments on commit b7919bd

Please sign in to comment.