@@ -132,13 +132,43 @@ void canister_init() {
132
132
void health () {
133
133
IC_API ic_api (CanisterQuery{std::string (__func__)}, false );
134
134
IC_API::debug_print (" llama2 is healthy!" );
135
- ic_api.to_wire (CandidTypeBool{true });
135
+
136
+ CandidTypeRecord status_code_record;
137
+ status_code_record.append (" status_code" ,
138
+ CandidTypeNat16{Http::StatusCode::OK});
139
+ ic_api.to_wire (CandidTypeVariant{" Ok" , status_code_record});
136
140
}
137
141
138
142
// readiness endpoint (ready for inference & NFT Collection initialized
139
143
void ready () {
140
144
IC_API ic_api (CanisterQuery{std::string (__func__)}, false );
141
- bool ready = ready_for_inference && p_nft_collection &&
142
- p_nft_collection->initialized && is_canister_mode_set ();
143
- ic_api.to_wire (CandidTypeBool{ready});
145
+
146
+ if (!ready_for_inference) {
147
+ std::string error_msg =
148
+ " Model not yet uploaded or initialize endpoint not yet called" ;
149
+ ic_api.to_wire (CandidTypeVariant{
150
+ " Err" , CandidTypeVariant{" Other" , CandidTypeText{error_msg}}});
151
+ return ;
152
+ }
153
+
154
+ if (!is_canister_mode_set ()) {
155
+ std::string error_msg = " canister_mode is not yet set" ;
156
+ ic_api.to_wire (CandidTypeVariant{
157
+ " Err" , CandidTypeVariant{" Other" , CandidTypeText{error_msg}}});
158
+ return ;
159
+ }
160
+
161
+ if (is_canister_mode_nft_ordinal ()) {
162
+ if (!(p_nft_collection && p_nft_collection->initialized )) {
163
+ std::string error_msg =
164
+ " canister_mode=nft_ordinal, but nft_collection is not initialized" ;
165
+ ic_api.to_wire (CandidTypeVariant{
166
+ " Err" , CandidTypeVariant{" Other" , CandidTypeText{error_msg}}});
167
+ return ;
168
+ }
169
+ }
170
+ CandidTypeRecord status_code_record;
171
+ status_code_record.append (" status_code" ,
172
+ CandidTypeNat16{Http::StatusCode::OK});
173
+ ic_api.to_wire (CandidTypeVariant{" Ok" , status_code_record});
144
174
}
0 commit comments