Validation and errors

Comatype validates on both sides of the wire, using the same schema.

WhenWhat is validatedIf invalid
Before the client sendsparams search headers bodyThrows a validation error without any network call
After the server receivesSame as aboveReturns 400 without calling the handler
Before the server respondsThe handler's return value (status, body, headers)Returns 500 (the details are not shown)
After the client receivesBody and headersThrows a validation error

Shape of a validation error#

An error says where it is wrong.

LanguageTypeLocation
TypeScript / JavaScriptValidationErrorpath (body.email, params.id, tags[0])
Go*comatype.ValidationErrorPath
PythonComatypeValidationErrorpath
Rustcomatype::Error::Validation(ValidationError)path
Java / Kotlincomatype.ValidationExceptionpath
SwiftValidationErrorpath
RubyComatype::ValidationErrorpath
C#Comatype.ValidationExceptionPath

What the server answers#

SituationResponse
Invalid input400 { "code": "validation_error", "message": "...", "path": "body.email" }
The body is not JSON400 { "code": "invalid_json", ... }
The path does not match404 { "code": "not_found", ... }
The path matches but the method differs405 (with an Allow header)
An exception in a handler, or a response that does not match the .comat500 { "code": "internal_error", "message": "Internal Server Error" }

This 400 is not part of the Response of the .comat.

Strictness#

  • Bodies are strict about JSON types. The string "5" is not turned into an int (the same in Python, TypeScript and Go).
  • Paths, queries and headers arrive as strings, so they are converted to int / bool / arrays before validation.
  • int64 and decimal are strings on the wire, and sending them as numbers is invalid.
  • Extra keys are skipped (they are not an error).
  • A missing required key, or null where null is not allowed, is invalid.

Exceptions on the client#

ExceptionMeaning
Validation errorThe input before sending is invalid, or the response received is invalid
UnexpectedStatusErrorA status you did not pass to the call came back (it has status and body)
ComatypeErrorWrong usage (the wrong method, a missing wrapper, no base url, and so on)