Our user authentication implementation so far does the required functionality, however if something is wrong and an error occurs, it doesn't tell you what's wrong. So we are going to add the code to retrieve the error message from our .NET code.
The .NET code sends out a JSON object at the end of the copy operation that indicates the status of the invocation. When you are creating your own service later on, make sure that you follow the same pattern. The status consists of two values:
- A boolean value that indicates if the service completes successfully.
- A string value that indicates the error message if the service fails to complete.
Create a reusable part called ExternalServiceInvocationStatus to represent the invocation status. You will use this reusable part in all your services.
Place the following code in the new reusable part:
Function Options(*DIRECT) Begin_Com Role(*EXTENDS #PRIM_OBJT)
* Variables to hold the OK & ErrorMessage values Define_Com Class(#PRIM_BOLN) Name(#gOK) Define_Com Class(#PRIM_DC.UnicodeString) Name(#gErrorMessage) * Properties: OK & ErrorMessage Define_Pty Name(OK) Get(*AUTO #gOK) Set(*AUTO #gOK) Define_Pty Name(ErrorMessage) Get(*AUTO #gErrorMessage) Set(*AUTO #gErrorMessage) * Routine to read the OK status & error message from the HTTP response object Mthroutine Name(FromHttpResponse) Define_Map For(*INPUT) Class(#XPRIM_HttpResponse) Name(#HttpResponse) Pass(*BY_REFERENCE) Define_Com Class(#XPRIM_RandomAccessJsonReader) Name(#Json) * Initiaiize properties #gOK := False #gErrorMessage := '' * Check if any response… If (#HttpResponse.IsSuccessfulRequest) * Read the response JSON #Json.SetSourceHttpResponse HttpResponse(#HttpResponse) * Check if request returns OK status code If (#HttpResponse.IsSuccessHttpStatusCode) #gOK := True Else * Read error message from the JSON response #gErrorMessage := #Json.ReadStringWithName( 'errorMessage' ) Endif Else #gErrorMessage := #HttpResponse.ErrorMessage Endif Endroutine End_Com
Next: Adjusting the User's Authenticate Method to Read Invocation Status in HTTP Response
