Geben Sie das Modell (bezogen auf this):Ulme: erhalten erste Fehlermeldung aus einer Liste
type alias ValidationResult =
{ parameter : String
, errorMessage : String
}
type alias ErrorResponse =
{ validationErrors : List ValidationResult }
decodeValidationResults : Decoder ValidationResult
decodeValidationResults =
map2 ValidationResult
(field "Parameter" string)
(field "ErrorMessage" string)
decodeErrorResponse : Decoder ErrorResponse
decodeErrorResponse =
map ErrorResponse
(field "ValidationErrors" (list decodeValidationResults))
ich eine Funktion erstellen möchten, die die forst Fehlermeldung aus der Errorzurückgibt. Hier ist, was ich habe versucht:
firstErrorMessage : Decoder CardEngineErrorResponse -> String
firstErrorMessage decoder response =
case List.head response.validationErrors of
Just something ->
something.errorMessage
Nothing ->
toString ""
Aber ich bin immer die Fehlermeldung:
The definition of `firstErrorMessage` does not match its type annotation.
The type annotation for `firstErrorMessage` says it always returns:
String
But the returned value (shown above) is a:
{ b | validationErrors : List { a | errorMessage : String } } -> String
Hint: It looks like a function needs 1 more argument.
Jeder von euch haben eine Ahnung, was ich falsch mache?
Wenn Sie jemals nach Madrid kommen, bitte sagen Sie mir, denn ich besitze Sie Kisten Bier ;) –