Error: Collection not found , while using in-memory-web-api (not using any live api or json data )

491 Views Asked by At

i am trying to create dummy login from inmemory db angular without using any json file or live api for in memory service i am using users object

const users = [ 
      { id: 1, userName: 'abhijeet', password: 'abh@123'},
    ];

using http response

const url = `${environment.apiEndPoint}users?userName=^${user.userName}$&password=^${user.password}$`;
    this.http.get<UserDetails>(url).subscribe(resp => {
      let user = resp;

error is

{body: {…}, url: "/api/users?userName=^abhijeet$&password=^abh@123$", headers: HttpHeaders, status: 404, statusText: "Not Found"}
body:
error: "Collection 'undefined' not found"
__proto__: Object
headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}
status: 404
statusText: "Not Found"
url: "/api/users?userName=^abhijeet$&password=^abh@123$"

if i remove @ from password field and use underscore instead i am getting correct response but @ is not working for any filed.

1

There are 1 best solutions below

0
DevGo On

You should not use those @ in get calls of http. It will expects in form of encoding.

Also, it seems like your api call is login, dont use ^ for making query for logins, it works for like condition. But for login, it should exactly match the values.

try following, it will works

const url = `${environment.apiEndPoint}users?userName=${user.userName}$&password=encodeURI(${user.password})$`;
    this.http.get<UserDetails>(url).subscribe(resp => {
      let user = resp;