Change Format of API Error (#784)
This is a wire breaking change for json errors since we have removed and renamed a few fields, and changed part of the structure of the returned json error. * Remove redundant fields in Status, details.error_id, details.TraceId and details.request_id from API errors. * Added wrapped errors and "ops" field to indicate the internal operation of the errors returned by the API. * Added error cli error reporting of Op and wrapped errors.
This commit is contained in:
1 parent
18ea39b237
commit
aa4157639c
48 files changed
+742
-728
No files matched your search
@@ -148,7 +148,7 @@ func TestCrud(t *testing.T) {
|
||||
require.Error(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Status)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus())
|
||||
}
|
||||
|
||||
func TestErrors(t *testing.T) {
|
||||
@@ -171,7 +171,7 @@ func TestErrors(t *testing.T) {
|
||||
require.Error(err)
|
||||
apiErr := api.AsServerError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Status)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus())
|
||||
|
||||
// Create another resource with the same name.
|
||||
_, err = userClient.Create(tc.Context(), org.GetPublicId(), users.WithName("first"))
|
||||
@@ -183,17 +183,17 @@ func TestErrors(t *testing.T) {
|
||||
require.Error(err)
|
||||
apiErr = api.AsServerError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.Status)
|
||||
assert.EqualValues(http.StatusNotFound, apiErr.ResponseStatus())
|
||||
|
||||
_, err = userClient.Read(tc.Context(), "invalid id")
|
||||
require.Error(err)
|
||||
apiErr = api.AsServerError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusBadRequest, apiErr.Status)
|
||||
assert.EqualValues(http.StatusBadRequest, apiErr.ResponseStatus())
|
||||
|
||||
_, err = userClient.Update(tc.Context(), u.Item.Id, u.Item.Version)
|
||||
require.Error(err)
|
||||
apiErr = api.AsServerError(err)
|
||||
assert.NotNil(apiErr)
|
||||
assert.EqualValues(http.StatusBadRequest, apiErr.Status)
|
||||
assert.EqualValues(http.StatusBadRequest, apiErr.ResponseStatus())
|
||||
}
|
||||
Reference in new issue
Block a user