Skip to content

Commit

Permalink
task: error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
s.jovanoski committed Feb 23, 2024
1 parent 0b854bb commit deb770c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/httpClient.ts
@@ -1,3 +1,5 @@
import { convert } from '@feathersjs/errors';

export interface httpClientOptions {
hostname: string;
username?: string;
Expand Down Expand Up @@ -38,7 +40,9 @@ const request = async (options: RequestOptions) => {

if (!response.ok) {
logger({ statusCode: response.status, statusText: response.statusText });
throw new Error(`${response.status} ${response.statusText}`);
const error = new Error(`${response.status} ${response.statusText}`);
error.name = `${response.status}`;
throw convert(error);
}

return response.json();
Expand Down
5 changes: 3 additions & 2 deletions test/client.test.ts
Expand Up @@ -3,6 +3,7 @@ import assert from 'assert';
import { SolrService } from '../src';
import { httpClient } from '../src/httpClient';
import { createCore, deleteCore, addSchema, deleteSchema } from './seed';
import { FeathersError } from '@feathersjs/errors';

const options = {
host: 'http://localhost:8983/solr',
Expand Down Expand Up @@ -60,7 +61,7 @@ describe('client', () => {
await Client.get('/solr/notexist', {})
throw new Error(`Expected an error and didn't get one!`)
} catch (error: unknown) {
return assert.equal((error as Error).message, '404 Not Found')
return assert.equal((error as FeathersError).code, 404)
}
});

Expand Down Expand Up @@ -93,7 +94,7 @@ describe('client', () => {
});
throw new Error(`Expected an error and didn't get one!`)
} catch (error: unknown) {
return assert.equal((error as Error).message, '500 Server Error')
return assert.equal((error as FeathersError).code, 500)
}
});
});
Expand Down

0 comments on commit deb770c

Please sign in to comment.