You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@servicecomb.apache.org by GitBox <gi...@apache.org> on 2018/05/11 01:43:42 UTC

[GitHub] little-cui closed pull request #347: SCB-572 Can not convert error to status code

little-cui closed pull request #347: SCB-572 Can not convert error to status code
URL: https://github.com/apache/incubator-servicecomb-service-center/pull/347
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/server/error/error.go b/server/error/error.go
index b30356ee..a12662ca 100644
--- a/server/error/error.go
+++ b/server/error/error.go
@@ -18,7 +18,6 @@ package error
 
 import (
 	"encoding/json"
-	"net/http"
 )
 
 var errors = map[int32]string{
@@ -108,10 +107,7 @@ func (e Error) Marshal() []byte {
 }
 
 func (e Error) StatusCode() int {
-	if e.Code >= 500000 {
-		return http.StatusInternalServerError
-	}
-	return http.StatusBadRequest
+	return int(e.Code / 1000)
 }
 
 func (e Error) InternalError() bool {
diff --git a/server/error/error_test.go b/server/error/error_test.go
new file mode 100644
index 00000000..da0e6af5
--- /dev/null
+++ b/server/error/error_test.go
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package error
+
+import (
+	"net/http"
+	"testing"
+)
+
+func TestError_StatusCode(t *testing.T) {
+	e := Error{Code: 503999}
+	if e.StatusCode() != http.StatusServiceUnavailable {
+		t.Fatalf("TestError_StatusCode %v failed", e)
+	}
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services