Skip to content
This repository has been archived by the owner on Mar 21, 2021. It is now read-only.

Try-Catch not working as expected #466

Closed
levitesm opened this issue Oct 7, 2019 · 6 comments · Fixed by #543
Closed

Try-Catch not working as expected #466

levitesm opened this issue Oct 7, 2019 · 6 comments · Fixed by #543

Comments

@levitesm
Copy link

levitesm commented Oct 7, 2019

Hello!

I have a question regarding the code generated by JHipster.
I'm using the Vue.Js blueprint.

In all the services for each entity in frontend JHipster is generating several standard functions which look like this:

public update(entity: ICompetitors): Promise {
return new Promise(resolve => {
axios.put(${baseApiUrl}, entity).then(function(res) {
resolve(res.data);
}));
});
}

When I'm calling that function I'm doing something like this:

try {
await this.competitorsService().update(this.competitor);
} catch {
this.savingError = true;
}

But the CATCH is not working, because the promise created in the Update function is not rejected....
So to fix this, I need to change the generated Update function to this:

public update(entity: ICompetitors): Promise {
return new Promise((resolve, reject) => {
axios.put(${baseApiUrl}, entity).then(function(res) {
resolve(res.data);
}).catch(err => {reject(err.message)});
});
}

So my question is: why are those functions generated like this?
Why is not the Promise rejected in case of an error?
Is this a mistake in JHipster? Or were those functions intended to be used in a different way?

Thanks a lot for you help!!

Mark.

jhipster info
INFO! Using JHipster version installed locally in current project's node_modules
INFO! Executing jhipster:info
INFO! Options: from-cli: true
Welcome to the JHipster Information Sub-Generator

JHipster Version(s)
kompetitors-2@0.0.0 /Users/marklevites/RealProjects/Kompetitors2
└─┬ generator-jhipster-vuejs@1.1.0
  └── generator-jhipster@6.1.2 

JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "promptValues": {
      "packageName": "fr.ippon.kompetitors",
      "nativeLanguage": "en"
    },
    "jhipsterVersion": "6.2.0",
    "applicationType": "monolith",
    "baseName": "Kompetitors2",
    "packageName": "fr.ippon.kompetitors",
    "packageFolder": "fr/ippon/kompetitors",
    "serverPort": "8080",
    "authenticationType": "jwt",
    "cacheProvider": "ehcache",
    "enableHibernateCache": true,
    "websocket": false,
    "databaseType": "sql",
    "devDatabaseType": "h2Disk",
    "prodDatabaseType": "postgresql",
    "searchEngine": false,
    "messageBroker": false,
    "serviceDiscoveryType": false,
    "buildTool": "maven",
    "enableSwaggerCodegen": false,
    "jwtSecretKey": "bXktc2VjcmV0LXRva2VuLXRvLWNoYW5nZS1pbi1wcm9kdWN0aW9uLWFuZC10by1rZWVwLWluLWEtc2VjdXJlLXBsYWNl",
    "testFrameworks": [],
    "jhiPrefix": "jhi",
    "entitySuffix": "",
    "dtoSuffix": "DTO",
    "otherModules": [
      {
        "name": "generator-jhipster-vuejs",
        "version": "1.1.0"
      }
    ],
    "enableTranslation": true,
    "clientPackageManager": "npm",
    "nativeLanguage": "en",
    "languages": [
      "en",
      "fr",
      "ru"
    ],
    "blueprints": [
      {
        "name": "generator-jhipster-vuejs",
        "version": "1.1.0"
      }
    ]
  },
  "generator-jhipster-vuejs": {
    "jhipsterVersion": "6.1.2",
    "applicationType": "monolith",
    "baseName": "Kompetitors2",
    "useSass": true,
    "clientPackageManager": "npm",
    "clientFramework": "vue",
    "clientTheme": "none",
    "clientThemeVariant": ""
  }
}
JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions
entity GlobalGroups {
  name String required,
  logo AnyBlob,
  webSite String
}
entity Competitors {
  name String,
  webSite String,
  countryPhone String
}
entity Offices {
  name String,
  address String,
  phone String,
  numberEmployees Integer,
  numberConsultants Integer,
  numberTechnicals Integer,
  numberHR Integer,
  numberClients Integer,
  established LocalDate,
  isMainOffice Boolean
}
entity Legal {
  legalAddress String,
  siren String,
  greffe String,
  founded LocalDate,
  updateDate LocalDate,
  legalForm String
}
entity Finance {
  margin Double,
  ebitda Double,
  occupationRate Double,
  revenue Double,
  year Integer required
}
entity Clients {
  officeName String,
  name String required,
  since String,
  isIppon Boolean,
  updateDate LocalDate
}
entity ClientsProjects {
  status String
}
entity TechCompetancies
entity TechTools
entity TechServices
entity TechPartners
entity TechProjects
entity HrInfo {
  interviewsNumber Integer,
  recrutmentTime Integer,
  reviewedCvPercent Double,
  hrDetails String
}
entity PrInfo {
  fbNumber Integer,
  twitterNumber Integer,
  instaNumber Integer,
  youNumer Integer,
  linkedNumber Integer,
  date LocalDate
}
entity CompetitiveRates {
  totalRate Double,
  techRate Double,
  financeRate Double,
  clientsRate Double,
  hrRate Double
}
entity Dialogs {
  section String required,
  topic String required,
  message String required,
  author String required,
  date LocalDate
}
entity People {
  fName String required,
  lName String required,
  title String required,
  linkedPage String,
  isKey Boolean
}
entity ListCountries {
  value String required minlength(3)
}
entity ListCities {
  value String required minlength(3)
}
entity ListCityCountries {
  value String required minlength(3)
}
entity ListIndustries {
  value String required minlength(3)
}
entity ListOwnerships {
  value String required minlength(3)
}
entity ListActivities {
  value String required minlength(3)
}
entity ListPricings {
  value String required minlength(3)
}
entity ListProjectTypes {
  value String required minlength(3)
}
entity ListClientsProjectTypes {
  value String required minlength(3)
}
entity ListCompetancies {
  value String required minlength(3)
}
entity ListTools {
  value String required minlength(3)
}
entity ListTechPartners {
  value String required minlength(3)
}
entity ListServices {
  value String required minlength(3)
}
entity UserGroupRights {
  userGroupName String required,
  blockedSectionNumber Integer,
  blockedType BlockType
}
entity SocieteMain {
  siren String,
  deno String,
  greffe String,
  enseigne String,
  psiret String,
  adresse String,
  codepostal String,
  normcommune String,
  commune String,
  ape String,
  apetexte String,
  dateimmat String,
  dcren String,
  nationalite String,
  formejur String,
  capital String,
  devisecap String,
  typecap String,
  url String
}
enum BlockType {
  VIEW,
  EDIT
}

relationship OneToOne {
  Legal{competitor} to Competitors,
  HrInfo{competitor} to Competitors,
  CompetitiveRates{competitor} to Competitors,
  SocieteMain{competitor} to Competitors{societeMain}
}
relationship OneToMany {
  GlobalGroups{competitors} to Competitors{globalGroups},
  Competitors{offices} to Offices{competitors},
  Competitors{finance} to Finance{competitors},
  Offices{clients} to Clients{offices},
  Clients{projects} to ClientsProjects{clients},
  Offices{techCompetancies} to TechCompetancies{offices},
  Offices{techTools} to TechTools{offices},
  Offices{techServices} to TechServices{offices},
  Offices{techPartners} to TechPartners{offices},
  Offices{techProjects} to TechProjects{offices},
  Competitors{pr} to PrInfo{competitors},
  Competitors{dialogs} to Dialogs{competitors},
  Competitors{people} to People{competitors}
}
relationship ManyToOne {
  Competitors{country} to ListCountries,
  Offices{city} to ListCities,
  Legal{ownership} to ListOwnerships,
  Legal{activity} to ListActivities,
  Legal{pricing} to ListPricings,
  Clients{industry} to ListIndustries,
  ClientsProjects{projectType} to ListClientsProjectTypes,
  TechCompetancies{value} to ListCompetancies,
  TechTools{value} to ListTools,
  TechServices{value} to ListServices,
  TechPartners{value} to ListTechPartners,
  TechProjects{value} to ListProjectTypes,
  ListCities{country} to ListCityCountries
}


Environment and Tools

java version "12.0.1" 2019-04-16
Java(TM) SE Runtime Environment (build 12.0.1+12)
Java HotSpot(TM) 64-Bit Server VM (build 12.0.1+12, mixed mode, sharing)

git version 2.20.1 (Apple Git-117)

node: v10.15.3

npm: 6.10.3

Docker version 19.03.1, build 74b1e89

docker-compose version 1.24.1, build 4667896b

INFO! Congratulations, JHipster execution is complete!
MBP-Konstantin:Kompetitors2 marklevites$

@murdos
Copy link

murdos commented Oct 7, 2019

This issue seems related to https://github.com/jhipster/jhipster-vuejs.
I tried to transfer the issue there, but I can't, probably because I don't have enough rights on jhipster-vuejs project.

@pascalgrimaud pascalgrimaud transferred this issue from jhipster/generator-jhipster Oct 7, 2019
@pascalgrimaud
Copy link
Member

Thanks, I transfered the issue here

@atomfrede
Copy link
Member

Just to clarify, the

try {
await this.competitorsService().update(this.competitor);
} catch {
this.savingError = true;
}

is your custom code and not generated by jhipster-vuejs, right? I think the service classes we generate are intended to be used without async/await for now. See #447

@pascalgrimaud
Copy link
Member

@atomfrede : for your information, @hdurix suggested to @levitesm to open a ticket here, as there is maybe a missing part in our service, using Vue.js

@atomfrede
Copy link
Member

@pascalgrimaud Good to know, it indeed looks a little bit like we have something missing here.

@levitesm
Copy link
Author

levitesm commented Oct 7, 2019 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants