acme: include Problem in OrderError.Error

An ACME Order object can contain an error field when it is invalid.
Previously, OrderError.Error() ignored this field, making it difficult
to diagnose why an order failed. This change includes the problem
details if available.


Change-Id: I461fd02ef02251a2ba1e8cea39b5df8070938117
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/772880
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: Sean Liao <sean@liao.dev>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Daniel McCarney <daniel@binaryparadox.net>
diff --git a/acme/types.go b/acme/types.go
index 322640c..65d69b2 100644
--- a/acme/types.go
+++ b/acme/types.go
@@ -167,7 +167,11 @@
 }
 
 func (oe *OrderError) Error() string {
-	return fmt.Sprintf("acme: order %s status: %s", oe.OrderURL, oe.Status)
+	str := fmt.Sprintf("acme: order %s status: %s", oe.OrderURL, oe.Status)
+	if oe.Problem != nil {
+		str += fmt.Sprintf("; problem: %s", oe.Problem)
+	}
+	return str
 }
 
 // RateLimit reports whether err represents a rate limit error and
diff --git a/acme/types_test.go b/acme/types_test.go
index 59ce7e7..2a59f6f 100644
--- a/acme/types_test.go
+++ b/acme/types_test.go
@@ -217,3 +217,19 @@
 		t.Errorf("Unexpected error string: wanted %q, got %q", expectedStr, err.Error())
 	}
 }
+
+func TestOrderErrorProblem(t *testing.T) {
+	oe := &OrderError{
+		OrderURL: "url",
+		Status:   "invalid",
+		Problem: &Error{
+			StatusCode:  400,
+			ProblemType: "type",
+			Detail:      "detail",
+		},
+	}
+	want := "acme: order url status: invalid; problem: 400 type: detail"
+	if got := oe.Error(); got != want {
+		t.Errorf("oe.Error() = %q, want %q", got, want)
+	}
+}