mirror of
https://github.com/actions/actions-runner-controller.git
synced 2025-12-18 07:58:18 +00:00
Introduce new preview auto-scaling mode for ARC. (#2153)
Co-authored-by: Cory Miller <cory-miller@github.com> Co-authored-by: Nikola Jokic <nikola-jokic@github.com> Co-authored-by: Ava Stancu <AvaStancu@github.com> Co-authored-by: Ferenc Hammerl <fhammerl@github.com> Co-authored-by: Francesco Renzi <rentziass@github.com> Co-authored-by: Bassem Dghaidi <Link-@github.com>
This commit is contained in:
71
github/actions/errors.go
Normal file
71
github/actions/errors.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package actions
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ActionsError struct {
|
||||
ExceptionName string `json:"typeName,omitempty"`
|
||||
Message string `json:"message,omitempty"`
|
||||
StatusCode int
|
||||
}
|
||||
|
||||
func (e *ActionsError) Error() string {
|
||||
return fmt.Sprintf("%v - had issue communicating with Actions backend: %v", e.StatusCode, e.Message)
|
||||
}
|
||||
|
||||
func ParseActionsErrorFromResponse(response *http.Response) error {
|
||||
if response.ContentLength == 0 {
|
||||
message := "Request returned status: " + response.Status
|
||||
return &ActionsError{
|
||||
ExceptionName: "unknown",
|
||||
Message: message,
|
||||
StatusCode: response.StatusCode,
|
||||
}
|
||||
}
|
||||
|
||||
defer response.Body.Close()
|
||||
body, err := io.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
body = trimByteOrderMark(body)
|
||||
contentType, ok := response.Header["Content-Type"]
|
||||
if ok && len(contentType) > 0 && strings.Contains(contentType[0], "text/plain") {
|
||||
message := string(body)
|
||||
statusCode := response.StatusCode
|
||||
return &ActionsError{
|
||||
Message: message,
|
||||
StatusCode: statusCode,
|
||||
}
|
||||
}
|
||||
|
||||
actionsError := &ActionsError{StatusCode: response.StatusCode}
|
||||
if err := json.Unmarshal(body, &actionsError); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return actionsError
|
||||
}
|
||||
|
||||
type MessageQueueTokenExpiredError struct {
|
||||
msg string
|
||||
}
|
||||
|
||||
func (e *MessageQueueTokenExpiredError) Error() string {
|
||||
return e.msg
|
||||
}
|
||||
|
||||
type HttpClientSideError struct {
|
||||
msg string
|
||||
Code int
|
||||
}
|
||||
|
||||
func (e *HttpClientSideError) Error() string {
|
||||
return e.msg
|
||||
}
|
||||
Reference in New Issue
Block a user