1
0
mirror of https://github.com/IBM/fp-go.git synced 2025-08-10 22:31:32 +02:00

fix: initial release

Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
Dr. Carsten Leue
2023-07-17 18:03:21 +02:00
parent 69c2fe1118
commit 2efe4f64c5
18 changed files with 890 additions and 115 deletions

View File

@@ -35,6 +35,16 @@ var (
}),
)),
)
// ValidateJsonResponse checks if an HTTP response is a valid JSON response
ValidateJsonResponse = F.Flow2(
E.Of[error, *H.Response],
E.ChainFirst(F.Flow5(
GetHeader,
R.Lookup[H.Header](HeaderContentType),
O.Chain(A.First[string]),
E.FromOption[error, string](errors.OnNone("unable to access the [%s] header", HeaderContentType)),
E.ChainFirst(validateJsonContentTypeString),
)))
)
const (
@@ -64,16 +74,3 @@ func isValidStatus(resp *H.Response) bool {
func StatusCodeError(resp *H.Response) error {
return fmt.Errorf("invalid status code [%d] when accessing URL [%s]", resp.StatusCode, resp.Request.URL)
}
// ValidateJsonResponse checks if an HTTP response is a valid JSON response
func ValidateJsonResponse(resp *H.Response) E.Either[error, *H.Response] {
return F.Pipe6(
resp,
GetHeader,
R.Lookup[H.Header](HeaderContentType),
O.Chain(A.First[string]),
E.FromOption[error, string](errors.OnNone("unable to access the [%s] header", HeaderContentType)),
E.ChainFirst(validateJsonContentTypeString),
E.MapTo[error, string](resp),
)
}