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.
你們有任何想法,我做錯了什麼?
如果你永遠不會來皇馬,請告訴我,因爲我擁有你的箱子啤酒 ;) –