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

Throw errors instead of strings #3211

Merged
merged 1 commit into from Jan 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions assets/js/phoenix.js
Expand Up @@ -423,7 +423,7 @@ export class Channel {
*/
join(timeout = this.timeout){
if(this.joinedOnce){
throw(`tried to join multiple times. 'join' can only be called a single time per channel instance`)
throw new Error(`tried to join multiple times. 'join' can only be called a single time per channel instance`)
} else {
this.joinedOnce = true
this.rejoin(timeout)
Expand Down Expand Up @@ -493,7 +493,7 @@ export class Channel {
*/
push(event, payload, timeout = this.timeout){
if(!this.joinedOnce){
throw(`tried to push '${event}' to '${this.topic}' before joining. Use channel.join() before pushing events`)
throw new Error(`tried to push '${event}' to '${this.topic}' before joining. Use channel.join() before pushing events`)
}
let pushEvent = new Push(this, event, function(){ return payload }, timeout)
if(this.canPush()){
Expand Down Expand Up @@ -595,7 +595,7 @@ export class Channel {
*/
trigger(event, payload, ref, joinRef){
let handledPayload = this.onMessage(event, payload, ref, joinRef)
if(payload && !handledPayload){ throw("channel onMessage callbacks must return the payload, modified or unmodified") }
if(payload && !handledPayload){ throw new Error("channel onMessage callbacks must return the payload, modified or unmodified") }

for (let i = 0; i < this.bindings.length; i++) {
const bind = this.bindings[i]
Expand Down Expand Up @@ -1067,7 +1067,7 @@ export class LongPoll {
this.onerror()
this.closeAndRetry()
break
default: throw(`unhandled poll status ${status}`)
default: throw new Error(`unhandled poll status ${status}`)
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions assets/test/channel_test.js
Expand Up @@ -102,7 +102,7 @@ describe("join", () => {
it("throws if attempting to join multiple times", () => {
channel.join()

assert.throws(() => channel.join(), /tried to join multiple times/)
assert.throws(() => channel.join(), /^Error: tried to join multiple times/)
})

it("triggers socket push with channel params", () => {
Expand Down Expand Up @@ -926,7 +926,7 @@ describe("push", () => {
})

it("throws if channel has not been joined", () => {
assert.throws(() => channel.push("event", {}), /tried to push.*before joining/)
assert.throws(() => channel.push("event", {}), /^Error: tried to push.*before joining/)
})
})

Expand Down