fix(http/proto): return 404 if proto not found

pull/13008/head
zhulongcheng 2019-03-29 11:17:50 +08:00
parent 3ceae6198a
commit 10f79fdb9b
2 changed files with 34 additions and 1 deletions

View File

@ -128,7 +128,10 @@ func (s *ProtoService) findProto(ctx context.Context, id platform.ID) (*platform
}
}
return nil, &platform.Error{Msg: "proto not found"}
return nil, &platform.Error{
Msg: "proto not found",
Code: platform.ENotFound,
}
}
// CreateDashboardsFromProto creates instances of each dashboard in a proto.

View File

@ -203,6 +203,36 @@ func TestProtoHandler(t *testing.T) {
`,
},
},
{
name: "create dashboard with proto not found",
fields: fields{
ProtoService: &mock.ProtoService{
CreateDashboardsFromProtoFn: func(ctx context.Context, protoID, orgID platform.ID) ([]*platform.Dashboard, error) {
return nil, &platform.Error{
Msg: "proto not found",
Code: platform.ENotFound,
}
},
},
},
args: args{
method: "POST",
endpoint: "/api/v2/protos/0000000000000001/dashboards",
body: &createProtoResourcesRequest{
OrganizationID: 1,
},
},
wants: wants{
statusCode: http.StatusNotFound,
contentType: "application/json; charset=utf-8",
body: `
{
"code": "not found",
"message": "proto not found"
}
`,
},
},
}
for _, tt := range tests {