puerta/internal/door/errors.go

46 lines
847 B
Go
Raw Normal View History

2022-12-30 06:51:51 +00:00
// SPDX-License-Identifier: Apache-2.0
// Copyright © 2022 Roberto Hidalgo <nidito@un.rob.mx>
package door
import (
"fmt"
"net/http"
)
type ErrorCommunication struct {
2022-12-30 06:51:51 +00:00
during string
err error
}
func (err *ErrorCommunication) Error() string {
return fmt.Sprintf("could not get door status while %s: %s", err.during, err.err.Error())
2022-12-30 06:51:51 +00:00
}
func (err *ErrorCommunication) Code() int {
2022-12-30 06:51:51 +00:00
return http.StatusInternalServerError
}
func (err *ErrorCommunication) Name() string {
return "communication-error"
}
type ErrorAlreadyOpen struct{}
2022-12-30 06:51:51 +00:00
func (err *ErrorAlreadyOpen) Error() string {
2022-12-30 06:51:51 +00:00
return "door is already open"
}
func (err *ErrorAlreadyOpen) Code() int {
2022-12-30 06:51:51 +00:00
return http.StatusPreconditionFailed
}
func (err *ErrorAlreadyOpen) Name() string {
return "already-open"
}
type Error interface {
Error() string
Code() int
Name() string
}