casdoor / casdoor-go-sdk

Go client SDK for Casdoor
https://github.com/casdoor/casdoor
Apache License 2.0
82 stars 65 forks source link

feat: check error in getbytes function #67

Closed thanhtinhpas1 closed 1 year ago

thanhtinhpas1 commented 1 year ago

Relative to MR 1993 in Casdoor, currently the API can response error if facing problems. But we still do not check this right now, it can lead to a panic, this MR will cover this part.

Testing code:

func main() {
    casdoorsdk.InitConfig(
        "http://localhost:8000",
        "37fcf22637d98fc2c99e",
        "a272de88b58f360c06affc6cec5a68e048b5514f", 
        "cert-built-in",
        "built-in",
        "app-built-in");

    permissions, err := casdoorsdk.GetPermissions();
    if err != nil {
        fmt.Println(err.Error())
    } else {
        for _, permission := range permissions {
            fmt.Printf("%v\n", permission.Name)
        }
    }

    permissions, _, err = casdoorsdk.GetPaginationPermissions(0, 10, make(map[string]string, 0));
    if err != nil {
        fmt.Println(err.Error())
    } else {
        for _, permission := range permissions {
            fmt.Printf("%v\n", permission.Name)
        }
    }
}

When response body Response with status == error:

this is test error
this is test error

When response array permissions:

built-in-permission
built-in-permission
casbin-bot commented 1 year ago

@seriouszyx @ComradeProgrammer @Resulte please review

github-actions[bot] commented 1 year ago

:tada: This PR is included in version 0.24.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: