0

I'm a beginner in ETL, I'm tried to rest client API localhost:8080/student (POST) from a existing data (eg: like 100k data)

In case of bad request API localhost:8080/student (POST) returns response like this

{
    "errors": [
        {
            "code": "student id.not.found",
            "message": "student with branch id does not exist"
        }
    ],
    "statusCode": "BAD_REQUEST"
}


OR  this in case of authorization fails

{
    "error": "invalid_token",
    "error_description": "Cannot convert access token to JSON"
}

what is the best way to handle this?

i want to save the failed request somewhere and retry later.

also in case of direct error like 500 etc how can i handle this?

my current approach is to store the JSON response in some variable and search if the response contain anything name with error or error code and i'll consider it fail or should i just check the return HTTP response status code

current flow going like this

rest response is like this

this is how i'm trying to get error field but it's coming null every time

James Z
  • 12,209
  • 10
  • 24
  • 44
Himanshi
  • 84
  • 1
  • 2
  • 13

2 Answers2

1

You can use the step filter rows or switch / case to check if the response or status code is equals or contains an error that you expect, with that you can redirect your flow like the example below:

enter image description here

0

I'm not sure if it's the best way but able to resolve the problem. Instead of looking for pentaho function i just use javascript it worked for me.

I've set the http status of response in response_status sample value 400 and result has the complete response api returning sample { "error": "invalid_token", "error_description": "Cannot convert access token to JSON" }

script sample I've used

var sucess_status;
var error_description;
var errors_detail;
var http_status = JSON.stringify(response_status);
if( http_status.match('/^2/g')){
sucess_status ="true";
}else{
sucess_status ="false";
var obj = JSON.parse(response);
errors_detail= JSON.stringify(obj);              // case of 401

}

further to read complicated json read any complex json you can enhance the script refer Need to parse complex Json

Himanshi
  • 84
  • 1
  • 2
  • 13