logger auth error
This commit is contained in:
@ -57,8 +57,9 @@ func (app *Config) authenticate(w http.ResponseWriter, a AuthPayload) {
|
||||
Input: a,
|
||||
Addr: "http://authentication-service/authenticate",
|
||||
ErrCode: statusError{
|
||||
Code: http.StatusUnauthorized,
|
||||
Err: errors.New("invalid credentials"),
|
||||
ExpectedCode: http.StatusAccepted,
|
||||
ErrCode: http.StatusUnauthorized,
|
||||
Err: errors.New("invalid credentials"),
|
||||
},
|
||||
SuccessMsg: "Authenticated",
|
||||
}
|
||||
@ -66,12 +67,14 @@ func (app *Config) authenticate(w http.ResponseWriter, a AuthPayload) {
|
||||
}
|
||||
|
||||
func (app *Config) LogItem(w http.ResponseWriter, entry LogPayload) {
|
||||
log.Println(entry)
|
||||
loggerService := Microservice{
|
||||
Input: entry,
|
||||
Addr: "http://logger-service/log",
|
||||
ErrCode: statusError{
|
||||
Code: http.StatusInternalServerError,
|
||||
Err: errors.New("internal error"),
|
||||
ExpectedCode: http.StatusAccepted,
|
||||
ErrCode: http.StatusInternalServerError,
|
||||
Err: errors.New("internal error"),
|
||||
},
|
||||
SuccessMsg: "Logged!",
|
||||
}
|
||||
@ -79,8 +82,9 @@ func (app *Config) LogItem(w http.ResponseWriter, entry LogPayload) {
|
||||
}
|
||||
|
||||
type statusError struct {
|
||||
Code int
|
||||
Err error
|
||||
ExpectedCode int
|
||||
ErrCode int
|
||||
Err error
|
||||
}
|
||||
|
||||
type Microservice struct {
|
||||
@ -97,6 +101,7 @@ func (app *Config) callService(w http.ResponseWriter, ms Microservice) {
|
||||
app.errorJSON(w, err, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
log.Println(ms.Input)
|
||||
|
||||
// call the service
|
||||
req, err := http.NewRequest(
|
||||
@ -120,8 +125,8 @@ func (app *Config) callService(w http.ResponseWriter, ms Microservice) {
|
||||
log.Println(resp.Body)
|
||||
|
||||
// make sure we get back the correct status code
|
||||
if resp.StatusCode != http.StatusAccepted {
|
||||
app.errorJSON(w, ms.ErrCode.Err, ms.ErrCode.Code)
|
||||
if resp.StatusCode != ms.ErrCode.ExpectedCode {
|
||||
app.errorJSON(w, ms.ErrCode.Err, ms.ErrCode.ErrCode)
|
||||
return
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user