From 410dbfb0e780179a67ce26c040701c2c8f9bc863 Mon Sep 17 00:00:00 2001 From: Thomas De Meyer Date: Thu, 21 Mar 2024 11:02:09 +0100 Subject: [PATCH] feat: also handle 404 with a response body --- .../vrap/codegen/languages/go/client/ClientFileProducer.kt | 1 + .../io/vrap/codegen/languages/go/client/MethodRenderer.kt | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/languages/go/src/main/kotlin/io/vrap/codegen/languages/go/client/ClientFileProducer.kt b/languages/go/src/main/kotlin/io/vrap/codegen/languages/go/client/ClientFileProducer.kt index 56c94c88..6330cb08 100644 --- a/languages/go/src/main/kotlin/io/vrap/codegen/languages/go/client/ClientFileProducer.kt +++ b/languages/go/src/main/kotlin/io/vrap/codegen/languages/go/client/ClientFileProducer.kt @@ -73,6 +73,7 @@ class ClientFileProducer( | |// NewClient creates a new client based on the provided ClientConfig |func NewClient(cfg *ClientConfig) (*Client, error) { + | | userAgent := cfg.UserAgent | if userAgent == "" { | userAgent = GetUserAgent() diff --git a/languages/go/src/main/kotlin/io/vrap/codegen/languages/go/client/MethodRenderer.kt b/languages/go/src/main/kotlin/io/vrap/codegen/languages/go/client/MethodRenderer.kt index 2adee5a4..91abe5a8 100644 --- a/languages/go/src/main/kotlin/io/vrap/codegen/languages/go/client/MethodRenderer.kt +++ b/languages/go/src/main/kotlin/io/vrap/codegen/languages/go/client/MethodRenderer.kt @@ -321,6 +321,12 @@ class GoMethodRenderer( | } | return result, nil """.trimMargin() + } else if (it.second.toInt() == 404) { + // If status code is 404 and has a response body we return a sentinel value + """ + |case ${it.second.toInt()}: + | return ${returnValue}ErrNotFound + """.trimMargin() } else { // If status is failure and response body is defined we return the marshalled error """