Skip to main content

Messages

Messages, is a powerful yet simple feature of Fireback, which aims to organize the error messages across the app. Often in many backends, we do not provide clear, translated error messages for actions.

We recommend to add every possible error message that an backend (cli or http server) return into the module definition, and then translate them into different languages on the same place and give explanation.

At the 1.2.0, you cannot extend them from another file, but I think it's useful to be able to keep translation of the error messages outside of the project, for those projects are having many languages, but maybe will be provided in later versions of Fireback.

Define messages on the module:

Messages are enums available in module level, they will become available for everything, there for you need to put the messages of actions also in the the same object.

Entities support a field called messages, and you can defined entity based messages as well for more isolation.

messages:
dataTypeDoesNotExistsInFireback:
en: This data type does not exist in fireback. %name %location

When compiled, Fireback will create few objects in Golang which you could use later on (WorkspacesModule.dyno.go in this case)

...
const (
AlreadyConfirmed workspacesCode = "AlreadyConfirmed"
BodyIsMissing workspacesCode = "BodyIsMissing"
DataTypeDoesNotExistsInFireback workspacesCode = "DataTypeDoesNotExistsInFireback"
...

and Also:


var WorkspacesMessages = newWorkspacesMessageCode()

func newWorkspacesMessageCode() *workspacesMsgs {
return &workspacesMsgs{
DataTypeDoesNotExistsInFireback: ErrorItem{
"$": "DataTypeDoesNotExistsInFireback",
"en": "This data type does not exist in fireback. %name %location",
},

As you see, $ is the key of the error, which needs to be always present and is equal to uppercase of the key.

Later on, in your actions or other go codes you can use when IError is required:

return Create401Error(&WorkspacesMessages.DataTypeDoesNotExistsInFireback, []string{})