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

Preset - Select and Details button triggers broken functionality #202

Closed
JovicaConkic opened this issue Jan 28, 2022 · 4 comments
Closed
Assignees
Labels
bug Something isn't working released

Comments

@JovicaConkic
Copy link

JovicaConkic commented Jan 28, 2022

@mdasberg @Pineapples @Remco75 When user clicks on Select button of presets page, code throws error and we are having broken functionality.

main.6860696422ebb3f0.js:1 ERROR 
p1 {headers: Qa, status: 200, statusText: 'OK', url: 'http://localhost:4400/ngapimock/presets', ok: false,}
error: {error: SyntaxError: Unexpected token S in JSON at position 0 at JSON.parse (<anonymous>) at XMLHtt…, text: 'Selected preset [My test preset]'}
headers: Qa {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}
message: "Http failure during parsing for http://localhost:4400/ngapimock/presets"
name: "HttpErrorResponse"
ok: false
status: 200
statusText: "OK"
url: "http://localhost:4400/ngapimock/presets"
[[Prototype]]: xb

Problem is that PresetsService service selectPreset method is making HTTP request expecting (by default) json but actually receving text.

Solution:
Existing code:

/**
   * Selects the preset.
   * @param {SelectPresetRequest} request The request.
   * @return {Observable<Object>} observable The observable.
   */
  selectPreset(request: { name: string }): Observable<any> {
    return this.http.put(`${this.BASE_URL}/${PRESET_URI}`, request);
  }

should be:

/**
   * Selects the preset.
   * @param {SelectPresetRequest} request The request.
   * @return {Observable<Object>} observable The observable.
   */
  selectPreset(request: { name: string }): Observable<any> {
    return this.http.put(`${this.BASE_URL}/${PRESET_URI}`, request, {
      responseType: "text",
    });
  }

The other issue is when user clicks on presents page on Details button. Modal is broken when selected preset doesn't have defined variables object beside name and mocks property. variables are not mandatory not all presets will have it and it would be nice to have secured code when opening modal.

Solution:

In PresetDetailsComponent piece of code:

this.variablesDataSource.data = Object.keys(this.data.variables).map((key) => ({
      key: key,
      value: this.data.variables[key],
    }));

could be secured liek this:

this.variablesDataSource.data = (
      Object.keys(this.data.variables) || []
    ).map((key) => ({
      key: key,
      value: this.data.variables[key],
    }));

It would be really good to have those fixes in place. I would contribute with those fixes but it looks like it is impossible. Thanks in advance.

@mdasberg mdasberg added the bug Something isn't working label Jan 30, 2022
@mdasberg mdasberg self-assigned this Jan 30, 2022
github-actions bot pushed a commit that referenced this issue Jan 30, 2022
## [3.1.1](v3.1.0...v3.1.1) (2022-01-30)

### Bug Fixes

* [#202](#202) use text response instead of json ([#203](#203)) ([e4ebad9](e4ebad9))
@mdasberg
Copy link
Contributor

🎉 This issue has been resolved in version 3.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@mdasberg
Copy link
Contributor

@JovicaConkic could you verify if 3.1.1 fixes the issue?

@mdasberg mdasberg reopened this Jan 30, 2022
@JovicaConkic
Copy link
Author

Hi @mdasberg yes I just verified. Issue was fixed with v3.1.1 release. Thanks a lot.

@mdasberg
Copy link
Contributor

@JovicaConkic thanks for reporting it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

No branches or pull requests

2 participants