Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
255 changes: 159 additions & 96 deletions plugin/home/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions plugin/home/src/Status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type StatusProps = {
errorMessage: string | null;
};


export const Status = ({ network, loading, status, errorMessage }: StatusProps) => {

const getStatusIcon = () => {
Expand Down
7 changes: 3 additions & 4 deletions plugin/int/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"path/filepath"
"sync"

"github.com/massalabs/deweb-plugin/int/utils"
"github.com/massalabs/deweb-server/int/api/config"
serverErrors "github.com/massalabs/deweb-server/pkg/error"
"github.com/massalabs/station/pkg/logger"
"gopkg.in/yaml.v2"
)
Expand All @@ -16,7 +16,6 @@ const (
defaultAPIPort = 0

DefaultConfigFileName = "deweb_server_config.yaml"
connectionRefused = "connection refused"
)

type ServerConfigManager struct {
Expand Down Expand Up @@ -86,8 +85,8 @@ func (c *ServerConfigManager) refreshServerConfig() error {
serverConfig, err := loadConfig(getConfigPath(c.configDir))
if err != nil {
// If the error is due to the fact that node configured in config is down, load conf without node retrieved data
if utils.Contains(err.Error(), connectionRefused) {
logger.Debug("the massa node used in deweb server conf is down, loading config without node retrieved data")
if serverError, ok := err.(*serverErrors.ServerError); ok && serverError.ErrorCode == serverErrors.ErrNetworkConfigCode {
logger.Debug("the massa node used in deweb server config is down, loading config without node retrieved data")
serverConfig, err = config.LoadConfigWhitoutNodeFetchedData(getConfigPath(c.configDir))
if err != nil {
return fmt.Errorf("failed to load config without node retrieved data, error: %w", err)
Expand Down
19 changes: 19 additions & 0 deletions plugin/int/server/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,25 @@ func (m *ServerManager) SetLastError(err string) {
m.lastError = err
}

/*
Change conditionally and atomically the last error message.

If the last error message is the same as the checkLastError, set the last error message to the newErr.
@param checkLastError the last error message to check
@param newErr the new error message to set
@return true if the last error message was changed, false otherwise
*/
func (m *ServerManager) SetLastErrorIfEqual(checkLastError string, newErr string) bool {
m.mu.Lock()
defer m.mu.Unlock()

if m.lastError == checkLastError {
m.lastError = newErr
return true
}
return false
}

// GetServerPort retrieves the actual port the server is running on
func (m *ServerManager) GetServerPort() (uint32, error) {
m.mu.Lock()
Expand Down
6 changes: 5 additions & 1 deletion plugin/int/station/networkManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ func (np *NetworkManager) pollNetwork() {
if err == ErrStationNetworkDown {
np.serverManager.SetLastError(ErrStationNetworkDown.Error())
}
return
}

// if the last error is that the network retrieved from station is down, reset the last error to ""
np.serverManager.SetLastErrorIfEqual(ErrStationNetworkDown.Error(), "")
}

/*
Expand Down Expand Up @@ -139,8 +143,8 @@ func (np *NetworkManager) SyncServerConfNetworkWithStation(restartServer bool) e
"Changing massa node configuration from '%s' (%s) to '%s' (%s, the node currently used by station)",
currentNodeName,
currentConfig.NetworkInfos.NodeURL,
response.URL,
response.Name,
response.URL,
)
}

Expand Down
2 changes: 1 addition & 1 deletion plugin/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"description": "Your private access to DeWeb.",
"logo": "favicon.png",
"home": "",
"version": "0.4.9",
"version": "0.4.10",
"apispec": ""
}
5 changes: 3 additions & 2 deletions server/int/api/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/massalabs/deweb-server/int/utils"
pkgConfig "github.com/massalabs/deweb-server/pkg/config"
pkgErrors "github.com/massalabs/deweb-server/pkg/error"
"github.com/massalabs/station/pkg/logger"
yaml "gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -41,7 +42,7 @@ type YamlServerConfig struct {
func DefaultConfig() (*ServerConfig, error) {
networkInfos, err := pkgConfig.NewNetworkConfig(DefaultNetworkNodeURL)
if err != nil {
return nil, fmt.Errorf("failed to create network config: %w", err)
return nil, pkgErrors.NewServerError(fmt.Sprintf("unable to create network config: %v", err), pkgErrors.ErrNetworkConfigCode)
}

return &ServerConfig{
Expand Down Expand Up @@ -70,7 +71,7 @@ func LoadServerConfig(configPath string) (*ServerConfig, error) {
logger.Warnf("using default values for minimal fees, chain ID, and network version")
} else {
// return error and servrConfig with empty networkInfos
return nil, fmt.Errorf("failed to create network config: %w", err)
return nil, pkgErrors.NewServerError(fmt.Sprintf("unable to retrieve network config from node: %v", err), pkgErrors.ErrNetworkConfigCode)
}
}
Conf.NetworkInfos = networkInfos
Expand Down
18 changes: 18 additions & 0 deletions server/pkg/error/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package error

const (
ErrNetworkConfigCode = 1000
)

type ServerError struct {
Message string
ErrorCode int
}

func NewServerError(message string, errorCode int) *ServerError {
return &ServerError{Message: message, ErrorCode: errorCode}
}

func (e *ServerError) Error() string {
return e.Message
}