diff --git a/services/graph/pkg/identity/ldap_education_school.go b/services/graph/pkg/identity/ldap_education_school.go index bbdf3e01840..fe02f4b262b 100644 --- a/services/graph/pkg/identity/ldap_education_school.go +++ b/services/graph/pkg/identity/ldap_education_school.go @@ -171,7 +171,7 @@ func (i *LDAP) CreateEducationSchool(ctx context.Context, school libregraph.Educ } // UpdateEducationSchoolOperation contains the logic for which update operation to apply to a school -func (i *LDAP) UpdateEducationSchoolOperation( +func (i *LDAP) updateEducationSchoolOperation( schoolUpdate libregraph.EducationSchool, currentSchool libregraph.EducationSchool, ) schoolUpdateOperation { @@ -289,7 +289,7 @@ func (i *LDAP) UpdateEducationSchool(ctx context.Context, numberOrID string, sch } currentSchool := i.createSchoolModelFromLDAP(e) - switch i.UpdateEducationSchoolOperation(school, *currentSchool) { + switch i.updateEducationSchoolOperation(school, *currentSchool) { case tooManyValues: return nil, fmt.Errorf("school name and school number cannot be updated in the same request") case schoolUnchanged: diff --git a/services/graph/pkg/identity/ldap_education_school_test.go b/services/graph/pkg/identity/ldap_education_school_test.go index 8c67b93eea2..520cdc5c900 100644 --- a/services/graph/pkg/identity/ldap_education_school_test.go +++ b/services/graph/pkg/identity/ldap_education_school_test.go @@ -310,7 +310,7 @@ func TestUpdateEducationSchoolOperation(t *testing.T) { SchoolNumber: &tt.schoolNumber, } - operation := b.UpdateEducationSchoolOperation(schoolUpdate, currentSchool) + operation := b.updateEducationSchoolOperation(schoolUpdate, currentSchool) assert.Equal(t, tt.expectedOperation, operation) } } diff --git a/services/graph/pkg/service/v0/errorcode/errorcode.go b/services/graph/pkg/service/v0/errorcode/errorcode.go index f5e5b49d0bd..65b6beb5a4c 100644 --- a/services/graph/pkg/service/v0/errorcode/errorcode.go +++ b/services/graph/pkg/service/v0/errorcode/errorcode.go @@ -1,3 +1,4 @@ +// Package errorcode allows to deal with graph error codes package errorcode import ( @@ -13,6 +14,7 @@ import ( // ErrorCode defines code as used in MS Graph - see https://docs.microsoft.com/en-us/graph/errors?context=graph%2Fapi%2F1.0&view=graph-rest-1.0 type ErrorCode int +// Error defines a custom error struct, containing and MS Graph error code an a textual error message type Error struct { errorCode ErrorCode msg string @@ -79,6 +81,7 @@ var errorCodes = [...]string{ "preconditionFailed", } +// New constructs a new errorcode.Error func New(e ErrorCode, msg string) Error { return Error{ errorCode: e, @@ -86,7 +89,7 @@ func New(e ErrorCode, msg string) Error { } } -// Render writes an Graph ErrorObject to the response writer +// Render writes an Graph ErrorCode object to the response writer func (e ErrorCode) Render(w http.ResponseWriter, r *http.Request, status int, msg string) { innererror := map[string]interface{}{ "date": time.Now().UTC().Format(time.RFC3339), @@ -104,12 +107,14 @@ func (e ErrorCode) Render(w http.ResponseWriter, r *http.Request, status int, ms render.JSON(w, r, resp) } +// Render writes an Graph Error object to the response writer func (e Error) Render(w http.ResponseWriter, r *http.Request) { var status int switch e.errorCode { case AccessDenied: status = http.StatusForbidden - case InvalidRange: + case + InvalidRange: status = http.StatusRequestedRangeNotSatisfiable case InvalidRequest: status = http.StatusBadRequest @@ -125,10 +130,12 @@ func (e Error) Render(w http.ResponseWriter, r *http.Request) { e.errorCode.Render(w, r, status, e.msg) } +// String returns the string corresponding to the ErrorCode func (e ErrorCode) String() string { return errorCodes[e] } +// Error return the concatenation of the error string and optinal message func (e Error) Error() string { errString := errorCodes[e.errorCode] if e.msg != "" {