w3c-ccg / traceability-interop

Verifiable Credentials for Supply Chain Interoperability Specification for HTTP
https://w3id.org/traceability/interoperability
Other
28 stars 10 forks source link

Better error handling #41

Closed OR13 closed 2 years ago

OR13 commented 2 years ago

When errors occur, there should be helpful messages returned over http.

There should be an error message structure.

The structure should be used when handling 200 responses where the verification failed

There should also be a 400 error message structure, for cases where the client violates the api definition.

There should be test cases for errors, and each variant of an error.

There should be specific cases for revocation, expiration, preactivation.

OR13 commented 2 years ago

We use a structure like this internally:

VerificationResult:
      title: Verification Check
      description: Verification result for a Verifiable Credential
      type: array
      items:
        type: object
        properties:
          status:
            type: string
            example: 'good'
          title:
            type: string
            example: 'Activation'
          description:
            type: string
            example: 'This credential activated a month ago'

Turning checks into readable sentences improves devx, and ui rendering consistency.

OR13 commented 2 years ago

We need better error handling, we can't tell why things fail.

See https://github.com/w3c-ccg/vp-request-spec/pull/12

We need 400 errors with more information...

and 200 errors with more information....

we need better schemas for communicating failure and success of flows.

nissimsan commented 2 years ago

This is between the presenting parties: define happy path and sad path interactions. What are the 400 error we expect can occur? What are relevant error messages which will help resovle?

nissimsan commented 2 years ago

I might pick this up next time when I have better bandwidth.

OR13 commented 2 years ago

awaiting https://github.com/w3c-ccg/vc-api/pull/258

nissimsan commented 2 years ago

next step: port over VC API error schemas, add postman for testing

OR13 commented 2 years ago

Need to port over the schemas and write postman tests that produce errors for all documented error cases.

OR13 commented 2 years ago

We still need to port over some error examples, ideally covering verify errors such as revocation.

nissimsan commented 2 years ago

Necessary for addressing this:

OR13 commented 2 years ago

Use english language to describe error cases, then ensure that there is a postman collection that asserts the json structure for each error condition.

mkhraisha commented 2 years ago

Initial Error cases when issuing a credential:

requests:

responses:

OR13 commented 2 years ago

We have a generic error response today:

type: object
required:
  - code
  - message
properties:
  code:
    type: integer
    format: int32
  message:
    type: string
  details:
    type: object

IMO, its a best practice to make a table with error codes for each case, and publish detailed objects along with the code optionally... in higher security environments you just drop the details.

Here are some of the errors listed above, in yaml format:

errors:
  '/credentials/issue':
    - message: 'credential.@context is not present'
    - message: 'credential.type is not present'
    - message: 'credential.issaunceDate is not present'
    - message: 'issuer does not support requested suite'
    - message: 'revocation type requested that is not supported by the issuer'
    - message: 'credential subject is not an object or a string'
    - message: 'term not defined in context'
    - message: 'credential.credentialStatus cannot be present when requesting a revocable credential issuance'
    - message: 'credential.id is required when issuance a revocation list credential'
    - message: 'issuer of revocation list is not the same as issuer of revocable credential'
OR13 commented 2 years ago

Before we go further, an entire category of '400' errors is solved for by:

instance data is not of the required schema type

For example:

credential is not of type Credential.

Where Credential says, @context, issuer, issuanceDate are required.

I propose we solve for these kinds of errors consistnetly... a very common pattern looks like this:

(req, res)=>{
try {
  requireValidJSONSchema(req.body, IssueCredentialRequestBody)
} catch (e){
  res.400.send(message: e.message)  // JSON-Schema errors
}
try {
  issue(req.body)
} catch (e){
  res.400.send(message: e.message) // JSON-LD errors
}
nissimsan commented 2 years ago

I assigned 401 and 403 today as I was adding security. More can be added, so let's keep this open, will continue when the above is merged.

OR13 commented 2 years ago

I think this is blocked by having a negative test suite, and interesting jsons that produce 4xx errors when sent to the apis.

brownoxford commented 2 years ago

Self-assigning to begin work on negative test suite.

BenjaminMoe commented 2 years ago

I think that having specific error messages can drift easily, but I agree with @OR13 that a test suite is the logical step for addressing these details.

nissimsan commented 2 years ago

@brownoxford has some stuff he'll PR to indicate direction on this.

brownoxford commented 2 years ago

Draft PR #253 is where this will be added

brownoxford commented 2 years ago

I propose that we define generic values for the message field, and leave the description field up to the implementors. There would be quite a lot of very specific error messages that need to be maintained if we did not do that, and that seems counter-productive.

brownoxford commented 2 years ago

I think this is blocked by having a negative test suite, and interesting jsons that produce 4xx errors when sent to the apis.

Conformance test suite is implementing the negative tests with mutated JSON to produce 4xx errors, and BadRequest.yml, Unauthenticated.yml, and Unauthorized.yml have been updated to specify response code and message (leaving description up to implementor).

Can we close this issue?

nissimsan commented 2 years ago

Conformance tests will take this over. Closing.