From 5964b6c32a42cfbc0448efb8c38c80ce2888979c Mon Sep 17 00:00:00 2001 From: toktar Date: Thu, 21 Apr 2022 02:48:27 +0300 Subject: [PATCH] DEV-1172: fixes in error handling --- config.yaml | 2 +- docker/Dockerfile | 1 + main.go | 4 ++-- services/request_service.go | 21 ++++++++++++--------- types/constants.go | 2 +- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/config.yaml b/config.yaml index 6538afaa..db9d8dae 100644 --- a/config.yaml +++ b/config.yaml @@ -1,5 +1,5 @@ method: cheqd -listener: :1313 +listener: 0.0.0.0:1313 resolverPath: "/1.0/identifiers/:did" ledgerTimeout: 5s loglevel: debug diff --git a/docker/Dockerfile b/docker/Dockerfile index 00409d40..ccc703cc 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -38,5 +38,6 @@ COPY --from=builder /root /bin WORKDIR ${CHEQD_RESOLVER_HOME_DIR} USER cheqd-resolver +COPY config.yaml ${CHEQD_RESOLVER_HOME_DIR} EXPOSE 1313 ENTRYPOINT ["cheqd-did-resolver"] \ No newline at end of file diff --git a/main.go b/main.go index 1a508dff..e39be100 100644 --- a/main.go +++ b/main.go @@ -46,8 +46,8 @@ func main() { // Routes e.GET(didResolutionPath, func(c echo.Context) error { - didUrl := c.Param("did") - fmt.Println(didUrl) + didUrl := c.Request().URL.String() + fmt.Println(c.Request().URL.String()) accept := strings.Split(c.Request().Header.Get("accept"), ";")[0] var acceptOption types.ContentType if strings.Contains(accept, string(types.JSONLD)) { diff --git a/services/request_service.go b/services/request_service.go index f9754fb7..9ed2bac4 100644 --- a/services/request_service.go +++ b/services/request_service.go @@ -67,7 +67,7 @@ func (rs RequestService) prepareResolutionResult(did string, resolutionOptions t } func (rs RequestService) prepareDereferencingResult(did string, dereferencingOptions types.DereferencingOption) (string, error) { - + fmt.Println("Dereference") didDereferencing, err := rs.Dereference(did, dereferencingOptions) if err != nil { return "", err @@ -78,6 +78,10 @@ func (rs RequestService) prepareDereferencingResult(did string, dereferencingOpt return "", err } + if didDereferencing.DereferencingMetadata.ResolutionError != "" { + return createJsonDereferencing("", "", string(resolutionMetadata)), nil + } + contentStream, err := rs.didDocService.MarshallContentStream(didDereferencing.ContentStream, dereferencingOptions.Accept) if err != nil { return "", err @@ -88,10 +92,6 @@ func (rs RequestService) prepareDereferencingResult(did string, dereferencingOpt return "", err } - if didDereferencing.DereferencingMetadata.ResolutionError != "" { - contentStream, metadata = "", "" - } - return createJsonDereferencing(contentStream, metadata, string(resolutionMetadata)), nil } @@ -130,16 +130,19 @@ func (rs RequestService) Resolve(did string, resolutionOptions types.ResolutionO // https://w3c-ccg.github.io/did-resolution/#dereferencing func (rs RequestService) Dereference(didUrl string, dereferenceOptions types.DereferencingOption) (types.DidDereferencing, error) { did, path, query, fragmentId, err := cheqdUtils.TrySplitDIDUrl(didUrl) - if err != nil || !cheqdUtils.IsValidDIDUrl(didUrl, "", []string{}) { - dereferencingMetadata := types.NewDereferencingMetadata(didUrl, dereferenceOptions.Accept, types.ResolutionInvalidDID) - return types.DidDereferencing{DereferencingMetadata: dereferencingMetadata}, nil - } + fmt.Println(did, path, query, fragmentId) + // TODO: implement if path != "" || query != "" { dereferencingMetadata := types.NewDereferencingMetadata(didUrl, dereferenceOptions.Accept, types.DereferencingNotSupported) return types.DidDereferencing{DereferencingMetadata: dereferencingMetadata}, nil } + if err != nil || !cheqdUtils.IsValidDIDUrl(didUrl, "", []string{}) { + dereferencingMetadata := types.NewDereferencingMetadata(didUrl, dereferenceOptions.Accept, types.DereferencingInvalidDIDUrl) + return types.DidDereferencing{DereferencingMetadata: dereferencingMetadata}, nil + } + didResolution, err := rs.Resolve(did, types.ResolutionOption(dereferenceOptions)) if err != nil { return types.DidDereferencing{}, err diff --git a/types/constants.go b/types/constants.go index 831096f5..1e473a9c 100644 --- a/types/constants.go +++ b/types/constants.go @@ -11,7 +11,7 @@ const ( const ( DereferencingInvalidDIDUrl ErrorType = "invalidDidUrl" DereferencingFragmentNotFound ErrorType = "FragmentNotFound" - DereferencingNotSupported ErrorType = "UrlNotSupported" + DereferencingNotSupported ErrorType = "NotSupportedUrl" ) type ContentType string