mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-19 13:03:44 +00:00
Standardize HTTP error results, better rejection message when parsing validated strings (#2663)
1. When parsing a `ValidatedString` from JSON and it fails, include a message about the expected format of the string. - Reworked the classes using C#11 features to reduce the amount of boilerplate needed to add a new validated string type. 2. Change to use [RFC7807](https://www.rfc-editor.org/rfc/rfc7807) format for HTTP error responses. At the moment we returned the `Error` type which was undocumented. 3. Update CLI to parse RFC7807 responses. Old error looked like: ```console $ onefuzz containers create AbCd ERROR:cli:command failed: request did not succeed: HTTP 500 - ``` New error looks like: ```console $ onefuzz containers create AbCd ERROR:cli:command failed: request did not succeed (400: INVALID_REQUEST): Unable to parse 'AbCd' as a Container: Container name must be 3-63 lowercase letters, numbers, or non-consecutive hyphens (see: https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/resource-name-rules#microsoftstorage) ``` Closes #2661.
This commit is contained in:
@ -6,8 +6,7 @@ namespace FunctionalTests;
|
||||
|
||||
|
||||
public class TaskDetails {
|
||||
JsonElement _e;
|
||||
public TaskDetails() { }
|
||||
readonly JsonElement _e;
|
||||
public TaskDetails(JsonElement e) => _e = e;
|
||||
|
||||
public string Type => _e.GetStringProperty("type");
|
||||
@ -77,22 +76,20 @@ public class TaskDetails {
|
||||
|
||||
|
||||
public class TaskConfig : IFromJsonElement<TaskConfig> {
|
||||
JsonElement _e;
|
||||
public TaskConfig() { }
|
||||
readonly JsonElement _e;
|
||||
public TaskConfig(JsonElement e) => _e = e;
|
||||
public TaskConfig Convert(JsonElement e) => new TaskConfig(e);
|
||||
public static TaskConfig Convert(JsonElement e) => new(e);
|
||||
|
||||
public Guid JobId => _e.GetGuidProperty("job_id");
|
||||
public IEnumerable<Guid>? PrereqTasks => _e.GetEnumerableGuidProperty("prereq_tasks");
|
||||
}
|
||||
|
||||
public class OneFuzzTask : IFromJsonElement<OneFuzzTask> {
|
||||
JsonElement _e;
|
||||
readonly JsonElement _e;
|
||||
|
||||
public OneFuzzTask() { }
|
||||
public OneFuzzTask(JsonElement e) => _e = e;
|
||||
|
||||
public OneFuzzTask Convert(JsonElement e) => new OneFuzzTask(e);
|
||||
public static OneFuzzTask Convert(JsonElement e) => new(e);
|
||||
|
||||
public Guid JobId => _e.GetGuidProperty("job_id");
|
||||
public Guid TaskId => _e.GetGuidProperty("task_id");
|
||||
|
Reference in New Issue
Block a user