Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added get job error details method to JobEntity #383

Merged

Conversation

jasonfagerberg-toast
Copy link
Contributor

Changes

Please describe both what is changing and why this is important. Include:

  • Method added to JobEntity to call the get error details endpoint
  • JobError / JobErrorDescription json classes added to deserialize response
  • used same was as any other management API client method

References

Please include relevant links supporting this change such as a:

Testing

Can be tested by importing into a project that imports user into auth 0. Sending an import request with a malformed phoneNumber MFA factor. Then looking up resulting error details via this method

  • This change adds test coverage
  • This change has been tested on the latest version of the platform/language or why not

Checklist

@jimmyjames
Copy link
Contributor

Thanks for this! I'll review this in detail and try it out next week; the codecov checks are failing currently, probably because we're missing tests for the json deserialization (you can see examples of these types of tests in the com/auth0/json/mgmt/ package). Thanks again, I'll follow-up next week when I try it out 👍

Copy link
Contributor

@jimmyjames jimmyjames left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from the (minor) docs comment, this change looks good, thanks so much 🙏! I tried it out with a failed job, and it worked as expected. Unfortunately, when I tried to call getErrorDetails with the ID of a job that completed successfully, it resulted in an exception due to an error parsing the response body:

Request failed with status code 204: Failed to parse the response body.
com.auth0.exception.APIException: Request failed with status code 204: Failed to parse the response body.
	at com.auth0.net.ExtendedBaseRequest.parseResponse(ExtendedBaseRequest.java:72)
	at com.auth0.net.BaseRequest.execute(BaseRequest.java:35)
	at com.auth0.client.mgmt.ReproRolesIssueTest.getErrorDetailsForSuccessfulJob(ReproRolesIssueTest.java:52)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:110)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
	at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:119)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
	at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
	at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
	at java.lang.Thread.run(Thread.java:748)
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: No content to map due to end-of-input
 at [Source: (String)""; line: 1, column: 0]
	at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59)
	at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:4688)
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4586)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3548)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3531)
	at com.auth0.net.CustomRequest.readResponseBody(CustomRequest.java:60)
	at com.auth0.net.ExtendedBaseRequest.parseResponse(ExtendedBaseRequest.java:70)
	... 52 more

This is happening because the API is returning a 204 with an empty response body. I'm not sure off-hand to fix this, but it's something to address before we can merge this PR.

And just a heads-up that I'm heading out on holiday until mid next week; if we can't figure this out today I'll have to check back in when I return. Thanks again!

@jasonfagerberg-toast
Copy link
Contributor Author

Unfortunately, when I tried to call getErrorDetails with the ID of a job that completed successfully, it resulted in an exception due to an error parsing the response body:

Hmm, with the current setup of the client I am not sure this would be easy. Easiest soltion I can think of is to skip the object mapper if content length is 0. It would look something like this in CustomRequest.readResponseBody

    @Override
    protected T readResponseBody(ResponseBody body) throws IOException {
        if (body.contentLength() == 0) {
            return null;
        }
        String payload = body.string();
        return mapper.readValue(payload, tType);
    }

LMK what you think. I am a little weary about this change since it could cause bad responses = null body -> client NPEs

@jasonfagerberg-toast
Copy link
Contributor Author

Unfortunately, when I tried to call getErrorDetails with the ID of a job that completed successfully, it resulted in an exception due to an error parsing the response body:

Another option is to simply check that the job has a failure before calling the API. Return an empty list otherwise

@jasonfagerberg-toast
Copy link
Contributor Author

@jimmyjames I fixed the issue with an anonymous inner class + added a test. Let me know what you think! If you don't get to it before your holidays have a good break!

@jimmyjames
Copy link
Contributor

@jasonfagerberg-toast nice! Thanks again for this PR and being so responsive, really appreciate it 🙇. Going to merge this today, then I'll cut a new release next week when I return.

@jimmyjames jimmyjames merged commit d8005f0 into auth0:master Oct 12, 2021
@jasonfagerberg-toast jasonfagerberg-toast deleted the get-job-error-deatils-client branch October 12, 2021 19:36
@jimmyjames jimmyjames added this to the v1-Next milestone Oct 12, 2021
@lbalmaceda lbalmaceda linked an issue Oct 18, 2021 that may be closed by this pull request
@lbalmaceda lbalmaceda modified the milestones: v1-Next, 1.35.0 Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add client method for /api/v2/jobs/{id}/errors endpoint
4 participants