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:
@@ -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),
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user