|
2 | 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this |
3 | 3 | // file, You can obtain one at https://mozilla.org/MPL/2.0/. |
4 | 4 |
|
5 | | -use std::time::Duration; |
6 | | - |
| 5 | +use dropshot::{ErrorStatusCode, HttpError, HttpResponseError}; |
7 | 6 | use gateway_messages::UpdateStatus; |
8 | 7 | use omicron_uuid_kinds::MupdateUuid; |
9 | 8 | use schemars::JsonSchema; |
10 | 9 | use serde::{Deserialize, Serialize}; |
| 10 | +use std::time::Duration; |
11 | 11 | use tufaceous_artifact::ArtifactHash; |
12 | 12 | use uuid::Uuid; |
13 | 13 |
|
| 14 | +/// The error type returned by the `sp_component_reset()` MGS endpoint. |
| 15 | +#[derive( |
| 16 | + Debug, Clone, PartialEq, Eq, Serialize, JsonSchema, thiserror::Error, |
| 17 | +)] |
| 18 | +#[serde(tag = "state", rename_all = "snake_case")] |
| 19 | +pub enum SpComponentResetError { |
| 20 | + /// MGS refuses to reset its own sled's SP. |
| 21 | + #[error("cannot reset SP of the sled hosting MGS")] |
| 22 | + ResetSpOfLocalSled, |
| 23 | + |
| 24 | + /// Other dropshot errors. |
| 25 | + #[error("{internal_message}")] |
| 26 | + Other { |
| 27 | + message: String, |
| 28 | + error_code: Option<String>, |
| 29 | + |
| 30 | + // Skip serializing these fields, as they are used for the |
| 31 | + // `fmt::Display` implementation and for determining the status code, |
| 32 | + // respectively, rather than included in the response body: |
| 33 | + #[serde(skip)] |
| 34 | + internal_message: String, |
| 35 | + #[serde(skip)] |
| 36 | + status: ErrorStatusCode, |
| 37 | + }, |
| 38 | +} |
| 39 | + |
| 40 | +impl HttpResponseError for SpComponentResetError { |
| 41 | + fn status_code(&self) -> ErrorStatusCode { |
| 42 | + match self { |
| 43 | + SpComponentResetError::ResetSpOfLocalSled => { |
| 44 | + ErrorStatusCode::BAD_REQUEST |
| 45 | + } |
| 46 | + SpComponentResetError::Other { status, .. } => *status, |
| 47 | + } |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +impl From<HttpError> for SpComponentResetError { |
| 52 | + fn from(err: HttpError) -> Self { |
| 53 | + Self::Other { |
| 54 | + message: err.external_message, |
| 55 | + error_code: err.error_code, |
| 56 | + internal_message: err.internal_message, |
| 57 | + status: err.status_code, |
| 58 | + } |
| 59 | + } |
| 60 | +} |
| 61 | + |
14 | 62 | #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, JsonSchema)] |
15 | 63 | #[serde(tag = "state", rename_all = "snake_case")] |
16 | 64 | pub enum SpUpdateStatus { |
|
0 commit comments