File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
jobs/instances-snapshot-cleaner Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 11package main
22
33import (
4+ "encoding/json"
5+ "errors"
46 "fmt"
57 "os"
68 "strconv"
@@ -58,6 +60,23 @@ func main() {
5860 }
5961
6062 if err := cleanSnapshots (deleteAfterDays , instanceAPI ); err != nil {
63+ var precondErr * scw.PreconditionFailedError
64+
65+ if errors .As (err , & precondErr ) {
66+ fmt .Println ("\n Extracted Error Details:" )
67+ fmt .Println ("Precondition:" , precondErr .Precondition )
68+ fmt .Println ("Help Message:" , precondErr .HelpMessage )
69+
70+ // Decode RawBody (if available)
71+ if len (precondErr .RawBody ) > 0 {
72+ var parsedBody map [string ]interface {}
73+ if json .Unmarshal (precondErr .RawBody , & parsedBody ) == nil {
74+ fmt .Println ("RawBody (Decoded):" , parsedBody )
75+ } else {
76+ fmt .Println ("RawBody (Raw):" , string (precondErr .RawBody ))
77+ }
78+ }
79+ }
6180 panic (err )
6281 }
6382}
You can’t perform that action at this time.
0 commit comments