0
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))
我想创建一个从错误响应返回福斯特错误消息的功能。这里是我已经试过:
firstErrorMessage : Decoder CardEngineErrorResponse -> String
firstErrorMessage decoder response =
case List.head response.validationErrors of
Just something ->
something.errorMessage
Nothing ->
toString ""
但我得到的错误:
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.
你们有任何想法,我做错了什么?
如果你永远不会来皇马,请告诉我,因为我拥有你的箱子啤酒 ;) –