return res
This commit is contained in:
parent
86ddac0167
commit
ac4e26e77d
@ -72,9 +72,9 @@ func SendMessage(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
endpoint := channel.CreateMessage(int(ticket.Channel))
|
||||
err = endpoint.Request(store, &contentType, channel.CreateMessageBody{
|
||||
err, _ = endpoint.Request(store, &contentType, channel.CreateMessageBody{
|
||||
Content: content,
|
||||
}, nil, nil)
|
||||
}, nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ func TicketViewHandler(ctx *gin.Context) {
|
||||
var errorMessage string
|
||||
|
||||
endpoint := channel.GetChannelMessages(int(ticket.Channel))
|
||||
if err = endpoint.Request(store, nil, nil, &messages, nil); err != nil {
|
||||
if err, _ = endpoint.Request(store, nil, nil, &messages); err != nil {
|
||||
isError = true
|
||||
errorMessage = err.Error()
|
||||
}
|
||||
|
@ -177,8 +177,8 @@ func WebChatWs(ctx *gin.Context) {
|
||||
if webhook != nil {
|
||||
endpoint := webhooks.ExecuteWebhook(*webhook)
|
||||
|
||||
resChan := make(chan *http.Response)
|
||||
err = endpoint.Request(store, &contentType, webhooks.ExecuteWebhookBody{
|
||||
var res *http.Response
|
||||
err, res = endpoint.Request(store, &contentType, webhooks.ExecuteWebhookBody{
|
||||
Content: content,
|
||||
Username: store.Get("name").(string),
|
||||
AvatarUrl: store.Get("avatar").(string),
|
||||
@ -187,8 +187,7 @@ func WebChatWs(ctx *gin.Context) {
|
||||
Roles: make([]string, 0),
|
||||
Users: make([]string, 0),
|
||||
},
|
||||
}, nil, &resChan)
|
||||
res := <-resChan
|
||||
}, nil)
|
||||
|
||||
if res.StatusCode == 404 || res.StatusCode == 403 {
|
||||
go table.DeleteWebhookByUuid(ticket.Uuid)
|
||||
@ -199,9 +198,9 @@ func WebChatWs(ctx *gin.Context) {
|
||||
|
||||
if !success {
|
||||
endpoint := channel.CreateMessage(int(ticket.Channel))
|
||||
err = endpoint.Request(store, &contentType, channel.CreateMessageBody{
|
||||
err, _ = endpoint.Request(store, &contentType, channel.CreateMessageBody{
|
||||
Content: content,
|
||||
}, nil, nil)
|
||||
}, nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ func CallbackHandler(ctx *gin.Context) {
|
||||
|
||||
// Get ID + name
|
||||
var currentUser objects.User
|
||||
err = user.CurrentUser.Request(store, nil, nil, ¤tUser, nil)
|
||||
err, _ = user.CurrentUser.Request(store, nil, nil, ¤tUser)
|
||||
if err != nil {
|
||||
ctx.String(500, err.Error())
|
||||
return
|
||||
@ -85,7 +85,7 @@ func CallbackHandler(ctx *gin.Context) {
|
||||
// Cache guilds because Discord takes like 2 whole seconds to return then
|
||||
go func() {
|
||||
var guilds []objects.Guild
|
||||
err = user.CurrentUserGuilds.Request(store, nil, nil, &guilds, nil)
|
||||
err, _ = user.CurrentUserGuilds.Request(store, nil, nil, &guilds)
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
return
|
||||
|
@ -37,7 +37,7 @@ type Endpoint struct {
|
||||
Endpoint string
|
||||
}
|
||||
|
||||
func (e *Endpoint) Request(store sessions.Session, contentType *ContentType, body interface{}, response interface{}, rawResponse *chan *http.Response) error {
|
||||
func (e *Endpoint) Request(store sessions.Session, contentType *ContentType, body interface{}, response interface{}) (error, *http.Response) {
|
||||
url := BASE_URL + e.Endpoint
|
||||
|
||||
// Create req
|
||||
@ -51,13 +51,13 @@ func (e *Endpoint) Request(store sessions.Session, contentType *ContentType, bod
|
||||
if *contentType == ApplicationJson {
|
||||
raw, err := json.Marshal(body)
|
||||
if err != nil {
|
||||
return err
|
||||
return err, nil
|
||||
}
|
||||
encoded = raw
|
||||
} else if *contentType == ApplicationFormUrlEncoded {
|
||||
str, err := qs.Marshal(body)
|
||||
if err != nil {
|
||||
return err
|
||||
return err, nil
|
||||
}
|
||||
encoded = []byte(str)
|
||||
}
|
||||
@ -67,7 +67,7 @@ func (e *Endpoint) Request(store sessions.Session, contentType *ContentType, bod
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
return err, nil
|
||||
}
|
||||
|
||||
// Set content type and user agent
|
||||
@ -87,7 +87,7 @@ func (e *Endpoint) Request(store sessions.Session, contentType *ContentType, bod
|
||||
if err != nil {
|
||||
store.Clear()
|
||||
_ = store.Save()
|
||||
return errors.New("Please login again!")
|
||||
return errors.New("Please login again!"), nil
|
||||
}
|
||||
|
||||
store.Set("access_token", res.AccessToken)
|
||||
@ -109,18 +109,14 @@ func (e *Endpoint) Request(store sessions.Session, contentType *ContentType, bod
|
||||
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
return err, nil
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
content, err := ioutil.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
return err, nil
|
||||
}
|
||||
|
||||
if rawResponse != nil {
|
||||
*rawResponse<-res
|
||||
}
|
||||
|
||||
return json.Unmarshal(content, response)
|
||||
return json.Unmarshal(content, response), res
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ func IsPremiumGuild(store sessions.Session, guildIdRaw string, ch chan bool) {
|
||||
var g objects.Guild
|
||||
endpoint := guild.GetGuild(int(guildId))
|
||||
|
||||
endpoint.Request(store, nil, nil, &g, nil)
|
||||
endpoint.Request(store, nil, nil, &g)
|
||||
|
||||
ownerIdRaw = g.OwnerId
|
||||
go redis.Client.StoreGuild(g)
|
||||
|
Loading…
x
Reference in New Issue
Block a user