mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-06 09:22:42 +08:00
api handlers to register and unregister host from turn,added dockerfile
This commit is contained in:
48
turnserver/internal/errors/api_errors.go
Normal file
48
turnserver/internal/errors/api_errors.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package errors
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gravitl/netmaker/turnserver/internal/models"
|
||||
)
|
||||
|
||||
type ApiRespErr string
|
||||
|
||||
const (
|
||||
Internal ApiRespErr = "internal"
|
||||
BadRequest ApiRespErr = "badrequest"
|
||||
NotFound ApiRespErr = "notfound"
|
||||
UnAuthorized ApiRespErr = "unauthorized"
|
||||
Forbidden ApiRespErr = "forbidden"
|
||||
Unavailable ApiRespErr = "unavailable"
|
||||
)
|
||||
|
||||
// FormatError - formats into api error resp
|
||||
func FormatError(err error, errType ApiRespErr) models.ErrorResponse {
|
||||
|
||||
var status = http.StatusInternalServerError
|
||||
switch errType {
|
||||
case Internal:
|
||||
status = http.StatusInternalServerError
|
||||
case BadRequest:
|
||||
status = http.StatusBadRequest
|
||||
case NotFound:
|
||||
status = http.StatusNotFound
|
||||
case UnAuthorized:
|
||||
status = http.StatusUnauthorized
|
||||
case Forbidden:
|
||||
status = http.StatusForbidden
|
||||
case Unavailable:
|
||||
status = http.StatusServiceUnavailable
|
||||
default:
|
||||
status = http.StatusInternalServerError
|
||||
}
|
||||
|
||||
var response = models.ErrorResponse{
|
||||
Code: status,
|
||||
}
|
||||
if err != nil {
|
||||
response.Message = err.Error()
|
||||
}
|
||||
return response
|
||||
}
|
Reference in New Issue
Block a user