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"
|
|
|
|
)
|
|
|
|
|
2023-01-02 06:54:23 +00:00
|
|
|
type ErrorCommunication struct {
|
2022-12-30 06:51:51 +00:00
|
|
|
during string
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
|
2023-01-02 06:54:23 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2023-01-02 06:54:23 +00:00
|
|
|
func (err *ErrorCommunication) Code() int {
|
2022-12-30 06:51:51 +00:00
|
|
|
return http.StatusInternalServerError
|
|
|
|
}
|
|
|
|
|
2023-01-02 06:54:23 +00:00
|
|
|
func (err *ErrorCommunication) Name() string {
|
|
|
|
return "communication-error"
|
|
|
|
}
|
|
|
|
|
|
|
|
type ErrorAlreadyOpen struct{}
|
2022-12-30 06:51:51 +00:00
|
|
|
|
2023-01-02 06:54:23 +00:00
|
|
|
func (err *ErrorAlreadyOpen) Error() string {
|
2022-12-30 06:51:51 +00:00
|
|
|
return "door is already open"
|
|
|
|
}
|
|
|
|
|
2023-01-02 06:54:23 +00:00
|
|
|
func (err *ErrorAlreadyOpen) Code() int {
|
2022-12-30 06:51:51 +00:00
|
|
|
return http.StatusPreconditionFailed
|
|
|
|
}
|
2023-01-02 06:54:23 +00:00
|
|
|
|
|
|
|
func (err *ErrorAlreadyOpen) Name() string {
|
|
|
|
return "already-open"
|
|
|
|
}
|
|
|
|
|
|
|
|
type Error interface {
|
|
|
|
Error() string
|
|
|
|
Code() int
|
|
|
|
Name() string
|
|
|
|
}
|