Skip to content

Commit

Permalink
added new marshal error class
Browse files Browse the repository at this point in the history
  • Loading branch information
asadali214 committed Mar 1, 2024
1 parent 5751d5d commit 660e3b6
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions utilities/marshal_error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package utilities

import (
"fmt"
)

type MarshalError struct {
structName string
innerError error
}

func NewMarshalError(structName string, err error) MarshalError {
return MarshalError{
structName: structName,
innerError: err,
}
}

// Error implements the Error method for the error interface.
// It returns a string representation of the ApiError instance when used in an error context.
func (a MarshalError) Error() string {
indent := "\n\t=>"
switch a.innerError.(type) {
case MarshalError:
indent = "."
}
return fmt.Sprintf("%v %v %v", a.structName, indent, a.innerError)
}

0 comments on commit 660e3b6

Please sign in to comment.