wunderDB Error wdbErrors is currently constant, and error messages do not have the ability to show which field/entity/etc caused the error. For example, for Database Missing error (parent db for collection does not exist), the error is
DatabaseDoesNotExistsError = WdbError{
ErrCode: "databaseMissing",
ErrMessage: "database with ID doesn't exist",
HttpStatusCode: 404,
}
Here ErrMessage is constant/fixed and does not include the id which might not exists. This can be modified to make the message as a format and adding the required ID at the caller level so that the message comes as database with ID [databaseId] doesn't exist.
Possible Fixes/Solutions
The error message can be made into a string format (wherever required, and just plain string wherever not required), eg:
DatabaseDoesNotExistsError = WdbError{
ErrCode: "databaseMissing",
ErrMessage: "database with ID [%s] does not exist",
HttpStatusCode: 404,
}
Adding a Format(args) method on the wdbError struct to fill in the placeholders (%s / %i / %v) with the required value. Example
func (wdbe WdbError) Format(args ...interface{}) WdbError {
wdbe.ErrMessage = fmt.Sprintf(wdbe.ErrMessage, args...)
return wdbe
}
And at caller end
if exists, _ := wdb.Databases.CheckIfExists(databaseId); !exists {
return &er.DatabaseDoesNotExistsError.Format(databaseId)
}
The function name Format can be different to much more specific like Fill or TBD
wunderDB Error
wdbErrorsis currently constant, and error messages do not have the ability to show which field/entity/etc caused the error. For example, for Database Missing error (parent db for collection does not exist), the error isHere
ErrMessageis constant/fixed and does not include the id which might not exists. This can be modified to make the message as a format and adding the required ID at the caller level so that the message comes asdatabase with ID [databaseId] doesn't exist.Possible Fixes/Solutions
The error message can be made into a string format (wherever required, and just plain string wherever not required), eg:
Adding a
Format(args)method on thewdbErrorstruct to fill in the placeholders (%s/%i/%v) with the required value. ExampleAnd at caller end
The function name
Formatcan be different to much more specific likeFillor TBD