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