Into stores the result into obj, if possible. If obj is nil it is ignored. If the returned object is of type Status and has .Status != StatusSuccess, the additional information in Status will be used to enrich the error.
(obj runtime.Object)
| 1097 | // If the returned object is of type Status and has .Status != StatusSuccess, the |
| 1098 | // additional information in Status will be used to enrich the error. |
| 1099 | func (r Result) Into(obj runtime.Object) error { |
| 1100 | if r.err != nil { |
| 1101 | // Check whether the result has a Status object in the body and prefer that. |
| 1102 | return r.Error() |
| 1103 | } |
| 1104 | if r.decoder == nil { |
| 1105 | return fmt.Errorf("serializer for %s doesn't exist", r.contentType) |
| 1106 | } |
| 1107 | if len(r.body) == 0 { |
| 1108 | return fmt.Errorf("0-length response with status code: %d and content type: %s", |
| 1109 | r.statusCode, r.contentType) |
| 1110 | } |
| 1111 | |
| 1112 | out, _, err := r.decoder.Decode(r.body, nil, obj) |
| 1113 | if err != nil || out == obj { |
| 1114 | return err |
| 1115 | } |
| 1116 | // if a different object is returned, see if it is Status and avoid double decoding |
| 1117 | // the object. |
| 1118 | switch t := out.(type) { |
| 1119 | case *metav1.Status: |
| 1120 | // any status besides StatusSuccess is considered an error. |
| 1121 | if t.Status != metav1.StatusSuccess { |
| 1122 | return errors.FromObject(t) |
| 1123 | } |
| 1124 | } |
| 1125 | return nil |
| 1126 | } |
| 1127 | |
| 1128 | // WasCreated updates the provided bool pointer to whether the server returned |
| 1129 | // 201 created or a different response. |