@@ -3,6 +3,7 @@ package ota
33import (
44 "context"
55 "encoding/json"
6+ "errors"
67 "fmt"
78 "net/http"
89 "net/url"
@@ -23,12 +24,14 @@ func (s *State) GetReleaseAPIEndpoint() string {
2324}
2425
2526// getUpdateURL returns the update URL for the given parameters
26- func (s * State ) getUpdateURL (params UpdateParams ) (string , error ) {
27+ func (s * State ) getUpdateURL (params UpdateParams ) (string , error , bool ) {
2728 updateURL , err := url .Parse (s .releaseAPIEndpoint )
2829 if err != nil {
29- return "" , fmt .Errorf ("error parsing update metadata URL: %w" , err )
30+ return "" , fmt .Errorf ("error parsing update metadata URL: %w" , err ), false
3031 }
3132
33+ isCustomVersion := false
34+
3235 appTargetVersion := s .GetTargetVersion ("app" )
3336 if appTargetVersion != "" && params .AppTargetVersion == "" {
3437 params .AppTargetVersion = appTargetVersion
@@ -43,19 +46,21 @@ func (s *State) getUpdateURL(params UpdateParams) (string, error) {
4346 query .Set ("prerelease" , fmt .Sprintf ("%v" , params .IncludePreRelease ))
4447 if params .AppTargetVersion != "" {
4548 query .Set ("appVersion" , params .AppTargetVersion )
49+ isCustomVersion = true
4650 }
4751 if params .SystemTargetVersion != "" {
4852 query .Set ("systemVersion" , params .SystemTargetVersion )
53+ isCustomVersion = true
4954 }
5055 updateURL .RawQuery = query .Encode ()
5156
52- return updateURL .String (), nil
57+ return updateURL .String (), nil , isCustomVersion
5358}
5459
5560func (s * State ) fetchUpdateMetadata (ctx context.Context , params UpdateParams ) (* UpdateMetadata , error ) {
5661 metadata := & UpdateMetadata {}
5762
58- url , err := s .getUpdateURL (params )
63+ url , err , isCustomVersion := s .getUpdateURL (params )
5964 if err != nil {
6065 return nil , fmt .Errorf ("error getting update URL: %w" , err )
6166 }
@@ -77,6 +82,10 @@ func (s *State) fetchUpdateMetadata(ctx context.Context, params UpdateParams) (*
7782 }
7883 defer resp .Body .Close ()
7984
85+ if isCustomVersion && resp .StatusCode == http .StatusNotFound {
86+ return nil , ErrVersionNotFound
87+ }
88+
8089 if resp .StatusCode != http .StatusOK {
8190 return nil , fmt .Errorf ("unexpected status code: %d" , resp .StatusCode )
8291 }
@@ -189,7 +198,7 @@ func (s *State) doUpdate(ctx context.Context, params UpdateParams) error {
189198
190199 postRebootAction := & PostRebootAction {
191200 HealthCheck : "/device/status" ,
192- RedirectUrl : redirectUrl ,
201+ RedirectTo : redirectUrl ,
193202 }
194203
195204 if err := s .reboot (true , postRebootAction , 10 * time .Second ); err != nil {
@@ -241,7 +250,11 @@ func (s *State) getUpdateStatus(
241250 // Get remote metadata
242251 remoteMetadata , err := s .fetchUpdateMetadata (ctx , params )
243252 if err != nil {
244- err = fmt .Errorf ("error checking for updates: %w" , err )
253+ if err == ErrVersionNotFound || errors .Unwrap (err ) == ErrVersionNotFound {
254+ err = ErrVersionNotFound
255+ } else {
256+ err = fmt .Errorf ("error checking for updates: %w" , err )
257+ }
245258 return
246259 }
247260 appUpdate .url = remoteMetadata .AppURL
0 commit comments