Files
drivefs/error.go
Matheus Sampaio Queiroga 8894b92de6 update path manipulation
Signed-off-by: Matheus Sampaio Queiroga <srherobrine20@gmail.com>
2025-03-17 23:08:07 -03:00

69 lines
1.4 KiB
Go

package drivefs
import (
"io/fs"
"net/http"
"net/url"
"reflect"
"github.com/googleapis/gax-go/v2/apierror"
"golang.org/x/net/http2"
"google.golang.org/api/googleapi"
)
func ProcessErr(res *http.Response, err error) error {
if res != nil {
switch res.StatusCode {
case http.StatusNotFound:
return fs.ErrNotExist
case http.StatusTooManyRequests:
return fs.ErrPermission
}
}
urlErr := (*url.Error)(nil)
switch v := err.(type) {
case *url.Error:
urlErr = v
err = v.Err
case *apierror.APIError:
details := v.Details()
if details.QuotaFailure != nil {
return fs.ErrPermission
}
switch v.HTTPCode() {
case http.StatusNotFound:
return fs.ErrNotExist
case http.StatusTooManyRequests:
return fs.ErrPermission
}
err = v.Unwrap()
case *googleapi.Error:
switch v.Code {
case http.StatusNotFound:
return fs.ErrNotExist
case http.StatusTooManyRequests:
return fs.ErrPermission
}
err = v.Unwrap()
}
valueOf := reflect.ValueOf(err)
switch valueOf.Type().String() {
case "http.http2GoAwayError", "http2.GoAwayError":
return &http2.GoAwayError{
DebugData: valueOf.FieldByName("DebugData").String(),
ErrCode: http2.ErrCode(uint32(valueOf.FieldByName("ErrCode").Uint())),
LastStreamID: uint32(valueOf.FieldByName("LastStreamID").Uint()),
}
default:
if urlErr != nil {
urlErr.Err = err
err = urlErr
}
return err
}
}