Coder Social home page Coder Social logo

Comments (10)

tyduptyler13 avatar tyduptyler13 commented on June 2, 2024 2

I refactored our typescript client to dynamically determine the response type. Previously we were statically compiling the response handler into every call but now it just generically always uses the json handler (which can skip json parsing if the body isn't returning the correct content type).

We just rolled a release so it might be a little bit of time before we publish the changes, however I wrote a test to explicitly trigger the issue you were having and it doesn't explode anymore. I'll let you close this whenever you get a chance to verify the changes.

from fusionauth-typescript-client.

robotdan avatar robotdan commented on June 2, 2024 1

Thanks for the report @NickBolles - I want to say we've corrected this behavior.

The 404 status code is correct, but when we receive that status code from FusionAuth, the client should expect the body length to be 0.

If you still encounter this error let us know. Thanks!

from fusionauth-typescript-client.

NickBolles avatar NickBolles commented on June 2, 2024 1

I'll try it out. Thank you!

from fusionauth-typescript-client.

NickBolles avatar NickBolles commented on June 2, 2024 1

Thanks for confirming @Snazzypants I'll close

from fusionauth-typescript-client.

lilyannh avatar lilyannh commented on June 2, 2024

What version should be checking to see if this is fixed? I am also seeing this behavior - am on FusionAuth version 1.15.8 and @fusionauth/typescript-client 1.15.4

from fusionauth-typescript-client.

robotdan avatar robotdan commented on June 2, 2024

@Snazzypants you get a 404 and the client is attempting to deserialize the body and you see a similar exception as @NickBolles?

Can you provide an example snippet of code and the response or error you're seeing? Thanks.

@tyduptyler13 I was thinking this was something we fixed already. In the case of the Login API, or others - that may return a 404 w/out a body - the client should be able to handle that. Do you want to take a look when you get a free moment? Thanks.

from fusionauth-typescript-client.

NickBolles avatar NickBolles commented on June 2, 2024

@robotdan I haven't tried this again, but this seems like where the error would occur

/**
* A function that returns the JSON form of the response text.
*
* @param response
* @constructor
*/
async function ErrorJSONResponseHandler<ERT>(response: Response): Promise<ClientResponse<ERT>> {
  let clientResponse = new ClientResponse<ERT>();

  clientResponse.statusCode = response.status;
  clientResponse.exception = await response.json();

  return clientResponse;
}

Specifically this line:

clientResponse.exception = await response.json();

Edit: although this commit seems promising for a fix.
13511c1 it was also 14 days after opening this issue. Shod have been fixed in 1.15.8 then.

from fusionauth-typescript-client.

lilyannh avatar lilyannh commented on June 2, 2024

I've updated to 1.15.8 and still get this behavior.

Sample code using this library:

export function login(username: string, password: string, applicationId: string, tenantId: string) {
	client.setTenantId(tenantId);
	const requestBody = {
		loginId: username,
		password: password,
		applicationId
	}

	return client.login(requestBody)
	.then( clientResponse => {
		return {success response};
	})
	.catch( clientResponse => {
		console.log(clientResponse)
		return {error response}
	});
}

With invalid credentials, the console.log output in the catch block:

ClientResponse {
  statusCode: 404,
  exception: FetchError: invalid json response body at https://[url]/api/login reason: Unexpected end of JSON input
      at C:\jnl\app-backend\node_modules\node-fetch\lib\index.js:272:32
      at processTicksAndRejections (internal/process/task_queues.js:97:5) {     
    message: 'invalid json response body at https://[url]/api/login reason: Unexpected end of JSON input',
    type: 'invalid-json'
  }
}

When I hit the fusionauth server login endpoint directly with a wrong password, it returns a 404 with no body, as expected.

from fusionauth-typescript-client.

robotdan avatar robotdan commented on June 2, 2024

@tyduptyler13 can you take a look and see if this is still an issue, or perhaps we have a second issue to resolve?

from fusionauth-typescript-client.

lilyannh avatar lilyannh commented on June 2, 2024

just updated to 1.18.0 and this works great! Thanks! I can't close this issue, but if @NickBolles or @robotdan want to close this, I think that would be appropriate!

from fusionauth-typescript-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.