Skip to content

Commit

Permalink
DEV-1172: fixes in error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Toktar committed Apr 20, 2022
1 parent fe50ac4 commit 5964b6c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
method: cheqd
listener: :1313
listener: 0.0.0.0:1313
resolverPath: "/1.0/identifiers/:did"
ledgerTimeout: 5s
loglevel: debug
Expand Down
1 change: 1 addition & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
21 changes: 12 additions & 9 deletions services/request_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion types/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const (
const (
DereferencingInvalidDIDUrl ErrorType = "invalidDidUrl"
DereferencingFragmentNotFound ErrorType = "FragmentNotFound"
DereferencingNotSupported ErrorType = "UrlNotSupported"
DereferencingNotSupported ErrorType = "NotSupportedUrl"
)

type ContentType string
Expand Down

0 comments on commit 5964b6c

Please sign in to comment.